feat: add roots option to language-server config

pull/13426/head
hackeryarn 2025-04-27 11:16:31 -05:00
parent 95c8d9c9e9
commit 616cf52ba5
No known key found for this signature in database
GPG Key ID: 5F62AEDC40AE8C1C
4 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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<String>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub environment: HashMap<String, String>,
@ -470,6 +469,8 @@ pub struct LanguageServerConfiguration {
pub config: Option<serde_json::Value>,
#[serde(default = "default_timeout")]
pub timeout: u64,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub roots: Vec<String>,
#[serde(
default,
skip_serializing,

View File

@ -873,11 +873,17 @@ fn start_client(
) -> Result<NewClient, StartupError> {
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,

View File

@ -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