on master help sign in
allow specifying environment for language servers in language.toml (#4004)
16e13b9TotalKrill
book/src/languages.md+2−1
@@ -39,7 +39,7 @@ injection-regex = "^mylang$"
39file-types = ["mylang", "myl"]
39file-types = ["mylang", "myl"]
40comment-token = "#"
40comment-token = "#"
41indent = { tab-width = 2, unit = " " }
41indent = { tab-width = 2, unit = " " }
42−language-server = { command = "mylang-lsp", args = ["--stdio"] }
42+language-server = { command = "mylang-lsp", args = ["--stdio"], environment = { "ENV1" = "value1", "ENV2" = "value2" } }
43formatter = { command = "mylang-formatter" , args = ["--stdin"] }
43formatter = { command = "mylang-formatter" , args = ["--stdin"] }
44```
44```
45
45
@@ -99,6 +99,7 @@ The `language-server` field takes the following keys:
99| `args` | A list of arguments to pass to the language server binary |
99| `args` | A list of arguments to pass to the language server binary |
100| `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` |
100| `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` |
101| `language-id` | The language name to pass to the language server. Some language servers support multiple languages and use this field to determine which one is being served in a buffer |
101| `language-id` | The language name to pass to the language server. Some language servers support multiple languages and use this field to determine which one is being served in a buffer |
102+| `environment` | Any environment variables that will be used when starting the language server `{ "KEY1" = "Value1", "KEY2" = "Value2" }` |
102
103
103The top-level `config` field is used to configure the LSP initialization options. A `format`
104The top-level `config` field is used to configure the LSP initialization options. A `format`
104sub-table within `config` can be used to pass extra formatting options to
105sub-table within `config` can be used to pass extra formatting options to
helix-core/src/syntax.rs+2
@@ -207,6 +207,8 @@ pub struct LanguageServerConfiguration {
207 #[serde(default)]
207 #[serde(default)]
208 #[serde(skip_serializing_if = "Vec::is_empty")]
208 #[serde(skip_serializing_if = "Vec::is_empty")]
209 pub args: Vec<String>,
209 pub args: Vec<String>,
210+ #[serde(default, skip_serializing_if = "HashMap::is_empty")]
211+ pub environment: HashMap<String, String>,
210 #[serde(default = "default_timeout")]
212 #[serde(default = "default_timeout")]
211 pub timeout: u64,
213 pub timeout: u64,
212 pub language_id: Option<String>,
214 pub language_id: Option<String>,
helix-lsp/src/client.rs+3
@@ -42,10 +42,12 @@ pub struct Client {
42
42
43impl Client {
43impl Client {
44 #[allow(clippy::type_complexity)]
44 #[allow(clippy::type_complexity)]
45+ #[allow(clippy::too_many_arguments)]
45 pub fn start(
46 pub fn start(
46 cmd: &str,
47 cmd: &str,
47 args: &[String],
48 args: &[String],
48 config: Option<Value>,
49 config: Option<Value>,
50+ server_environment: HashMap<String, String>,
49 root_markers: &[String],
51 root_markers: &[String],
50 id: usize,
52 id: usize,
51 req_timeout: u64,
53 req_timeout: u64,
@@ -55,6 +57,7 @@ impl Client {
55 let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
57 let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
56
58
57 let process = Command::new(cmd)
59 let process = Command::new(cmd)
60+ .envs(server_environment)
58 .args(args)
61 .args(args)
59 .stdin(Stdio::piped())
62 .stdin(Stdio::piped())
60 .stdout(Stdio::piped())
63 .stdout(Stdio::piped())
helix-lsp/src/lib.rs+1
@@ -550,6 +550,7 @@ fn start_client(
550 &ls_config.command,
550 &ls_config.command,
551 &ls_config.args,
551 &ls_config.args,
552 config.config.clone(),
552 config.config.clone(),
553+ ls_config.environment.clone(),
553 &config.roots,
554 &config.roots,
554 id,
555 id,
555 ls_config.timeout,
556 ls_config.timeout,