From bf92f3cb497290409bc6906fcc89787dd1a99dac Mon Sep 17 00:00:00 2001 From: code4lala Date: Tue, 24 Mar 2026 01:03:57 +0800 Subject: [PATCH] feat: Support project-level ls_specific_settings (#1192) --- docs/02-usage/050_configuration.md | 7 +++++-- docs/03-special-guides/cpp_setup.md | 4 +++- src/serena/config/serena_config.py | 5 +++-- src/serena/project.py | 3 ++- src/serena/resources/project.template.yml | 6 ++++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/02-usage/050_configuration.md b/docs/02-usage/050_configuration.md index 3a1598f3..4f52f1ec 100644 --- a/docs/02-usage/050_configuration.md +++ b/docs/02-usage/050_configuration.md @@ -213,8 +213,10 @@ This ensures backward compatibility: existing projects that already have a `.ser Most users will not need to adjust these settings. ::: -Under the key `ls_specific_settings` in `serena_config.yml`, you can you pass per-language, -language server-specific configuration. +Under the key `ls_specific_settings` in `serena_config.yml`, you can you pass global per-language, +language server-specific configuration. You can use the same key in the project configuration files (`project.yml` +and `project.local.yml` ) to override or extend the global settings for a specific project. +The settings are merged on top-level, meaning that project-level settings for a language will replace global settings for the same language. Structure: @@ -230,6 +232,7 @@ Most settings are currently undocumented. Please refer to the implementation to determine supported settings. ::: +(override-ls-path)= #### Overriding the Language Server Path Some language servers, particularly those that use a single core path for the language server (e.g. the main executable), diff --git a/docs/03-special-guides/cpp_setup.md b/docs/03-special-guides/cpp_setup.md index 916040d4..c54f2105 100644 --- a/docs/03-special-guides/cpp_setup.md +++ b/docs/03-special-guides/cpp_setup.md @@ -15,6 +15,8 @@ for cross-file reference finding, see below for details. Your project must have a `compile_commands.json` file at the repository root. This file is essential for correct parsing and cross-file reference finding. +You can use a specific clangd or ccls installation (e.g., a custom build or a version provided by your project), +by specifying the path in your configuration, see [ls-specific-settings](ls-specific-settings) for details. ## compile_commands.json Requirements @@ -27,7 +29,7 @@ For reliable cross-file reference finding with clangd, your `compile_commands.js ### With clangd -Serena automatically downloads and manages clangd. Since clangd does not properly work with relative paths in `compile_commands.json`, +By default, Serena automatically downloads and manages clangd. Since clangd does not properly work with relative paths in `compile_commands.json`, Serena will detect them and transform them into absolute paths automatically (writing a new `compile_commands.json` file), if needed. #### Customizing the Compilation Database Location diff --git a/src/serena/config/serena_config.py b/src/serena/config/serena_config.py index e863308d..be026c8a 100644 --- a/src/serena/config/serena_config.py +++ b/src/serena/config/serena_config.py @@ -222,6 +222,8 @@ class SharedConfig(ModeSelectionDefinition, ToolInclusionDefinition, ToStringMix language_backend: LanguageBackend | None = None line_ending: LineEnding | None = None read_only_memory_patterns: list[str] = field(default_factory=list) + ls_specific_settings: dict = field(default_factory=dict) + """Advanced configuration option allowing to configure language server implementation specific options, see SolidLSPSettings for more info.""" class SerenaConfigError(Exception): @@ -459,6 +461,7 @@ class ProjectConfig(SharedConfig): base_modes=data["base_modes"], default_modes=data["default_modes"], symbol_info_budget=symbol_info_budget, + ls_specific_settings=data.get("ls_specific_settings", {}), _local_override_keys=local_override_keys, ) @@ -678,8 +681,6 @@ class SerenaConfig(SharedConfig): Even though the value of the max_answer_chars can be changed when calling the tool, it may make sense to adjust this default through the global configuration. """ - ls_specific_settings: dict = field(default_factory=dict) - """Advanced configuration option allowing to configure language server implementation specific options, see SolidLSPSettings for more info.""" ignored_paths: list[str] = field(default_factory=list) """List of paths to ignore across all projects. Same syntax as gitignore, so you can use * and **. diff --git a/src/serena/project.py b/src/serena/project.py index 00d8ba40..d33e157f 100644 --- a/src/serena/project.py +++ b/src/serena/project.py @@ -624,13 +624,14 @@ class Project(ToStringMixin): log.info(f"Creating language server manager for {self.project_root}") self._language_server_manager_init_error = None + ls_specific_settings = {**self.serena_config.ls_specific_settings, **self.project_config.ls_specific_settings} factory = LanguageServerFactory( project_root=self.project_root, project_data_path=self._serena_data_folder, encoding=self.project_config.encoding, ignored_patterns=self._ignored_patterns, ls_timeout=ls_timeout, - ls_specific_settings=self.serena_config.ls_specific_settings, + ls_specific_settings=ls_specific_settings, trace_lsp_communication=self.serena_config.trace_lsp_communication, ) self.language_server_manager = LanguageServerManager.from_languages(self.project_config.languages, factory) diff --git a/src/serena/resources/project.template.yml b/src/serena/resources/project.template.yml index 78fea480..c6f74300 100644 --- a/src/serena/resources/project.template.yml +++ b/src/serena/resources/project.template.yml @@ -46,6 +46,12 @@ language_backend: # whether to use project's .gitignore files to ignore files ignore_all_files_in_gitignore: true +# advanced configuration option allowing to configure language server-specific options. +# Maps the language key to the options. +# Have a look at the docstring of the constructors of the LS implementations within solidlsp (e.g., for C# or PHP) to see which options are available. +# No documentation on options means no options are available. +ls_specific_settings: {} + # list of additional paths to ignore in this project. # Same syntax as gitignore, so you can use * and **. # Note: global ignored_paths from serena_config.yml are also applied additively.