From 616cf52ba54b83651d25053e61947a1097f65720 Mon Sep 17 00:00:00 2001 From: hackeryarn Date: Sun, 27 Apr 2025 11:16:31 -0500 Subject: [PATCH 1/2] feat: add roots option to language-server config --- book/src/languages.md | 1 + helix-core/src/syntax.rs | 5 +++-- helix-lsp/src/lib.rs | 8 +++++++- languages.toml | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/book/src/languages.md b/book/src/languages.md index 8db121ce1..16b5ecc17 100644 --- a/book/src/languages.md +++ b/book/src/languages.md @@ -132,6 +132,7 @@ These are the available options for a language server. | `config` | Language server initialization options | | `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` | | `environment` | Any environment variables that will be used when starting the language server `{ "KEY1" = "Value1", "KEY2" = "Value2" }` | +| `roots` | A set of marker files to look for when trying to find the workspace root. These apply befory `language.roots` ga| | `required-root-patterns` | A list of `glob` patterns to look for in the working directory. The language server is started if at least one of them is found. | A `format` sub-table within `config` can be used to pass extra formatting options to diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 677cdfa0b..63316a019 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -461,8 +461,7 @@ where #[serde(rename_all = "kebab-case")] pub struct LanguageServerConfiguration { pub command: String, - #[serde(default)] - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub args: Vec, #[serde(default, skip_serializing_if = "HashMap::is_empty")] pub environment: HashMap, @@ -470,6 +469,8 @@ pub struct LanguageServerConfiguration { pub config: Option, #[serde(default = "default_timeout")] pub timeout: u64, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub roots: Vec, #[serde( default, skip_serializing, diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 1a2557de2..f6368c7a6 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -873,11 +873,17 @@ fn start_client( ) -> Result { let (workspace, workspace_is_cwd) = helix_loader::find_workspace(); let workspace = path::normalize(workspace); + let mut roots = config.roots.clone(); + if !ls_config.roots.is_empty() { + let mut ls_roots = ls_config.roots.clone(); + ls_roots.append(&mut roots); + roots = ls_roots; + }; let root = find_lsp_workspace( doc_path .and_then(|x| x.parent().and_then(|x| x.to_str())) .unwrap_or("."), - &config.roots, + &roots, config.workspace_lsp_roots.as_deref().unwrap_or(root_dirs), &workspace, workspace_is_cwd, diff --git a/languages.toml b/languages.toml index 680d0dcd8..d81b643b1 100644 --- a/languages.toml +++ b/languages.toml @@ -90,7 +90,7 @@ pkl-lsp = { command = "pkl-lsp" } prisma-language-server = { command = "prisma-language-server", args = ["--stdio"] } purescript-language-server = { command = "purescript-language-server", args = ["--stdio"] } pylsp = { command = "pylsp" } -pyright = { command = "pyright-langserver", args = ["--stdio"], config = {} } +pyright = { command = "pyright-langserver", args = ["--stdio"], config = {}, roots = ["pyrightconfig.json"] } protols = { command = "protols", args = [] } basedpyright = { command = "basedpyright-langserver", args = ["--stdio"], config = {} } pylyzer = { command = "pylyzer", args = ["--server"] } @@ -931,7 +931,7 @@ scope = "source.python" injection-regex = "py(thon)?" file-types = ["py", "pyi", "py3", "pyw", "ptl", "rpy", "cpy", "ipy", "pyt", { glob = ".python_history" }, { glob = ".pythonstartup" }, { glob = ".pythonrc" }, { glob = "*SConstruct" }, { glob = "*SConscript" }, { glob = "*sconstruct" }] shebangs = ["python", "uv"] -roots = ["pyproject.toml", "setup.py", "poetry.lock", "pyrightconfig.json"] +roots = ["pyproject.toml", "setup.py", "poetry.lock"] comment-token = "#" language-servers = ["ruff", "jedi", "pylsp"] # TODO: pyls needs utf-8 offsets From de851bd561d27bce8ab96d47810007891b521493 Mon Sep 17 00:00:00 2001 From: Artem Chernyak Date: Sat, 14 Jun 2025 15:10:32 +0000 Subject: [PATCH 2/2] remove extra characters in docs Co-authored-by: Isaac Corbrey --- book/src/languages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/languages.md b/book/src/languages.md index 16b5ecc17..038f0bd6d 100644 --- a/book/src/languages.md +++ b/book/src/languages.md @@ -132,7 +132,7 @@ These are the available options for a language server. | `config` | Language server initialization options | | `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` | | `environment` | Any environment variables that will be used when starting the language server `{ "KEY1" = "Value1", "KEY2" = "Value2" }` | -| `roots` | A set of marker files to look for when trying to find the workspace root. These apply befory `language.roots` ga| +| `roots` | A set of marker files to look for when trying to find the workspace root. These apply befory `language.roots` | | `required-root-patterns` | A list of `glob` patterns to look for in the working directory. The language server is started if at least one of them is found. | A `format` sub-table within `config` can be used to pass extra formatting options to