on master help sign in
allow specifying environment for language servers in language.toml (#4004)

Signed-off-by: Stephen Wakely <fungus.humungus@gmail.com> Co-authored-by: Stephen Wakely <fungus.humungus@gmail.com> Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>

commit16e13b9789359282cb6c2681262f46fb1b70134b authorTotalKrill <kristoffer.odmark90@gmail.com> dateFri 9 Dec 2022, 05:09 (4 years ago) parent2ea20a2
4 files changed+8−1
book/src/languages.md+2−1 helix-core/src/syntax.rs+2 helix-lsp/src/client.rs+3 helix-lsp/src/lib.rs+1
book/src/languages.md+2−1
@@ -39,7 +39,7 @@ injection-regex = "^mylang$"
3939file-types = ["mylang", "myl"]
4040comment-token = "#"
4141indent = { 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" } }
4343formatter = { command = "mylang-formatter" , args = ["--stdin"] }
4444```
4545
@@ -99,6 +99,7 @@ The `language-server` field takes the following keys:
9999| `args` | A list of arguments to pass to the language server binary |
100100| `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` |
101101| `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" }` |
102103
103104The top-level `config` field is used to configure the LSP initialization options. A `format`
104105sub-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 {
207207 #[serde(default)]
208208 #[serde(skip_serializing_if = "Vec::is_empty")]
209209 pub args: Vec<String>,
210+ #[serde(default, skip_serializing_if = "HashMap::is_empty")]
211+ pub environment: HashMap<String, String>,
210212 #[serde(default = "default_timeout")]
211213 pub timeout: u64,
212214 pub language_id: Option<String>,
helix-lsp/src/client.rs+3
@@ -42,10 +42,12 @@ pub struct Client {
4242
4343impl Client {
4444 #[allow(clippy::type_complexity)]
45+ #[allow(clippy::too_many_arguments)]
4546 pub fn start(
4647 cmd: &str,
4748 args: &[String],
4849 config: Option<Value>,
50+ server_environment: HashMap<String, String>,
4951 root_markers: &[String],
5052 id: usize,
5153 req_timeout: u64,
@@ -55,6 +57,7 @@ impl Client {
5557 let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
5658
5759 let process = Command::new(cmd)
60+ .envs(server_environment)
5861 .args(args)
5962 .stdin(Stdio::piped())
6063 .stdout(Stdio::piped())
helix-lsp/src/lib.rs+1
@@ -550,6 +550,7 @@ fn start_client(
550550 &ls_config.command,
551551 &ls_config.args,
552552 config.config.clone(),
553+ ls_config.environment.clone(),
553554 &config.roots,
554555 id,
555556 ls_config.timeout,