zig: Wire up LSP settings
and binary.{path/arguments}
for zls
(#14379)
Enables the LSP `settings` and `binary.{path/arguments}` functionality Example: ``` "lsp": { "zls": { "settings": { "semantic_tokens": "none" }, "binary": { "path": "/home/user/zls/zig-out/bin/zls", "arguments": ["--enable-debug-log"] } } }, ``` Release Notes: - N/A
This commit is contained in:
parent
315692d112
commit
684d9dde56
1 changed files with 37 additions and 7 deletions
|
@ -1,6 +1,5 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use zed::LanguageServerId;
|
use zed_extension_api::{self as zed, serde_json, settings::LspSettings, LanguageServerId, Result};
|
||||||
use zed_extension_api::{self as zed, Result};
|
|
||||||
|
|
||||||
struct ZigExtension {
|
struct ZigExtension {
|
||||||
cached_binary_path: Option<String>,
|
cached_binary_path: Option<String>,
|
||||||
|
@ -9,6 +8,7 @@ struct ZigExtension {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ZlsBinary {
|
struct ZlsBinary {
|
||||||
path: String,
|
path: String,
|
||||||
|
args: Option<Vec<String>>,
|
||||||
environment: Option<Vec<(String, String)>>,
|
environment: Option<Vec<(String, String)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,11 +18,27 @@ impl ZigExtension {
|
||||||
language_server_id: &LanguageServerId,
|
language_server_id: &LanguageServerId,
|
||||||
worktree: &zed::Worktree,
|
worktree: &zed::Worktree,
|
||||||
) -> Result<ZlsBinary> {
|
) -> Result<ZlsBinary> {
|
||||||
|
let mut args: Option<Vec<String>> = None;
|
||||||
|
let environment = Some(worktree.shell_env());
|
||||||
|
|
||||||
|
if let Ok(lsp_settings) = LspSettings::for_worktree("zls", worktree) {
|
||||||
|
if let Some(binary) = lsp_settings.binary {
|
||||||
|
args = binary.arguments;
|
||||||
|
if let Some(path) = binary.path {
|
||||||
|
return Ok(ZlsBinary {
|
||||||
|
path: path.clone(),
|
||||||
|
args,
|
||||||
|
environment,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(path) = worktree.which("zls") {
|
if let Some(path) = worktree.which("zls") {
|
||||||
let environment = worktree.shell_env();
|
|
||||||
return Ok(ZlsBinary {
|
return Ok(ZlsBinary {
|
||||||
path,
|
path,
|
||||||
environment: Some(environment),
|
args,
|
||||||
|
environment,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +46,8 @@ impl ZigExtension {
|
||||||
if fs::metadata(&path).map_or(false, |stat| stat.is_file()) {
|
if fs::metadata(&path).map_or(false, |stat| stat.is_file()) {
|
||||||
return Ok(ZlsBinary {
|
return Ok(ZlsBinary {
|
||||||
path: path.clone(),
|
path: path.clone(),
|
||||||
environment: None,
|
args,
|
||||||
|
environment,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +121,8 @@ impl ZigExtension {
|
||||||
self.cached_binary_path = Some(binary_path.clone());
|
self.cached_binary_path = Some(binary_path.clone());
|
||||||
Ok(ZlsBinary {
|
Ok(ZlsBinary {
|
||||||
path: binary_path,
|
path: binary_path,
|
||||||
environment: None,
|
args,
|
||||||
|
environment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,10 +142,22 @@ impl zed::Extension for ZigExtension {
|
||||||
let zls_binary = self.language_server_binary(language_server_id, worktree)?;
|
let zls_binary = self.language_server_binary(language_server_id, worktree)?;
|
||||||
Ok(zed::Command {
|
Ok(zed::Command {
|
||||||
command: zls_binary.path,
|
command: zls_binary.path,
|
||||||
args: vec![],
|
args: zls_binary.args.unwrap_or_default(),
|
||||||
env: zls_binary.environment.unwrap_or_default(),
|
env: zls_binary.environment.unwrap_or_default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn language_server_workspace_configuration(
|
||||||
|
&mut self,
|
||||||
|
_language_server_id: &zed::LanguageServerId,
|
||||||
|
worktree: &zed::Worktree,
|
||||||
|
) -> Result<Option<serde_json::Value>> {
|
||||||
|
let settings = LspSettings::for_worktree("zls", worktree)
|
||||||
|
.ok()
|
||||||
|
.and_then(|lsp_settings| lsp_settings.settings.clone())
|
||||||
|
.unwrap_or_default();
|
||||||
|
Ok(Some(settings))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zed::register_extension!(ZigExtension);
|
zed::register_extension!(ZigExtension);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue