From f015fabd4514220fcdcb350e24520b86e74b53c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= Date: Wed, 28 Sep 2022 15:44:40 +0200 Subject: [PATCH 1/7] allow specifying environment for language servers in language.toml --- book/src/languages.md | 3 ++- helix-core/src/syntax.rs | 2 ++ helix-lsp/src/client.rs | 7 +++++++ helix-lsp/src/lib.rs | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/book/src/languages.md b/book/src/languages.md index 73c8121311e5..c02bba9b43b7 100644 --- a/book/src/languages.md +++ b/book/src/languages.md @@ -39,7 +39,7 @@ injection-regex = "^mylang$" file-types = ["mylang", "myl"] comment-token = "#" indent = { tab-width = 2, unit = " " } -language-server = { command = "mylang-lsp", args = ["--stdio"] } +language-server = { command = "mylang-lsp", args = ["--stdio"], envs = [["ENV1", "value1"],["ENV2", "value2"]] } formatter = { command = "mylang-formatter" , args = ["--stdin"] } ``` @@ -73,6 +73,7 @@ The `language-server` field takes the following keys: | `args` | A list of arguments to pass to the language server binary | | `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` | | `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 | +| `envs` | Any environment variables that will be used when starting the language server as an array of key/value pairs [["Key", "Value"], ["Key", "Value"]] | The top-level `config` field is used to configure the LSP initialization options. 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 e0a984d20d29..be2f2118f173 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -124,6 +124,8 @@ pub struct LanguageServerConfiguration { #[serde(default)] #[serde(skip_serializing_if = "Vec::is_empty")] pub args: Vec, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub envs: Vec<(String, String)>, #[serde(default = "default_timeout")] pub timeout: u64, pub language_id: Option, diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 497ce80cfb68..cf7b66258f5a 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -46,6 +46,7 @@ impl Client { cmd: &str, args: &[String], config: Option, + server_envs: &[(String, String)], root_markers: &[String], id: usize, req_timeout: u64, @@ -53,7 +54,13 @@ impl Client { // Resolve path to the binary let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?; + let server_envs: Vec<(String, String)> = server_envs + .into_iter() + .map(|(s1, s2)| (s1.clone(),s2.clone())) + .collect(); + let process = Command::new(cmd) + .envs(server_envs) .args(args) .stdin(Stdio::piped()) .stdout(Stdio::piped()) diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index cb2343573605..ed37566b5a7c 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -480,6 +480,7 @@ fn start_client( &ls_config.command, &ls_config.args, config.config.clone(), + &ls_config.envs, &config.roots, id, ls_config.timeout, From 858fe525cefc1ffa90d7263c9d081e71c62a95a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= Date: Fri, 30 Sep 2022 13:52:21 +0200 Subject: [PATCH 2/7] Fix fmt --- helix-lsp/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index cf7b66258f5a..e9e02de68a22 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -56,7 +56,7 @@ impl Client { let server_envs: Vec<(String, String)> = server_envs .into_iter() - .map(|(s1, s2)| (s1.clone(),s2.clone())) + .map(|(s1, s2)| (s1.clone(), s2.clone())) .collect(); let process = Command::new(cmd) From c9c8b2875ae1b11a0a1a678bc64ff4133e668467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= Date: Fri, 30 Sep 2022 22:33:36 +0200 Subject: [PATCH 3/7] fix clippy --- helix-lsp/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index e9e02de68a22..fd1312b545bf 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -55,7 +55,7 @@ impl Client { let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?; let server_envs: Vec<(String, String)> = server_envs - .into_iter() + .iter() .map(|(s1, s2)| (s1.clone(), s2.clone())) .collect(); From c752ef5b3ad48d4e36943a31f3c716835b351110 Mon Sep 17 00:00:00 2001 From: Stephen Wakely Date: Thu, 17 Nov 2022 09:57:49 +0000 Subject: [PATCH 4/7] Rename to environment and make it a hash table Signed-off-by: Stephen Wakely --- book/src/languages.md | 4 ++-- helix-core/src/syntax.rs | 4 ++-- helix-lsp/src/client.rs | 9 ++------- helix-lsp/src/lib.rs | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/book/src/languages.md b/book/src/languages.md index 61f4b48ad3d1..3336a6135f8f 100644 --- a/book/src/languages.md +++ b/book/src/languages.md @@ -39,7 +39,7 @@ injection-regex = "^mylang$" file-types = ["mylang", "myl"] comment-token = "#" indent = { tab-width = 2, unit = " " } -language-server = { command = "mylang-lsp", args = ["--stdio"], envs = [["ENV1", "value1"],["ENV2", "value2"]] } +language-server = { command = "mylang-lsp", args = ["--stdio"], environment = { "ENV1" = "value1", "ENV2" = "value2" } } formatter = { command = "mylang-formatter" , args = ["--stdin"] } ``` @@ -99,7 +99,7 @@ The `language-server` field takes the following keys: | `args` | A list of arguments to pass to the language server binary | | `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` | | `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 | -| `envs` | Any environment variables that will be used when starting the language server as an array of key/value pairs [["Key", "Value"], ["Key", "Value"]] | +| `environment` | Any environment variables that will be used when starting the language server as an object { "Key1" = "Value1", "Key2" = "Value2" } | The top-level `config` field is used to configure the LSP initialization options. 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 8eee58cf56b0..bc64a79b499f 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -204,8 +204,8 @@ pub struct LanguageServerConfiguration { #[serde(default)] #[serde(skip_serializing_if = "Vec::is_empty")] pub args: Vec, - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub envs: Vec<(String, String)>, + #[serde(default, skip_serializing_if = "HashMap::is_empty")] + pub environment: HashMap, #[serde(default = "default_timeout")] pub timeout: u64, pub language_id: Option, diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 32d5c3ab586b..fd9e01e0e225 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -46,7 +46,7 @@ impl Client { cmd: &str, args: &[String], config: Option, - server_envs: &[(String, String)], + server_environment: impl IntoIterator + Clone, root_markers: &[String], id: usize, req_timeout: u64, @@ -55,13 +55,8 @@ impl Client { // Resolve path to the binary let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?; - let server_envs: Vec<(String, String)> = server_envs - .iter() - .map(|(s1, s2)| (s1.clone(), s2.clone())) - .collect(); - let process = Command::new(cmd) - .envs(server_envs) + .envs(server_environment) .args(args) .stdin(Stdio::piped()) .stdout(Stdio::piped()) diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 30cb134cc64b..adcdd39096dc 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -513,7 +513,7 @@ fn start_client( &ls_config.command, &ls_config.args, config.config.clone(), - &ls_config.envs, + ls_config.environment.clone(), &config.roots, id, ls_config.timeout, From c51678aa79a5c8061d005c846c96fccda233a152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= Date: Tue, 22 Nov 2022 11:15:29 +0100 Subject: [PATCH 5/7] fix clippy warning --- helix-lsp/src/client.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index fd9e01e0e225..72629f754f24 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -42,6 +42,7 @@ pub struct Client { impl Client { #[allow(clippy::type_complexity)] + #[allow(clippy::too_many_arguments)] pub fn start( cmd: &str, args: &[String], From 516adf54051dc6b0fb4ef8be6a3a3932b024b079 Mon Sep 17 00:00:00 2001 From: TotalKrill Date: Mon, 5 Dec 2022 10:00:06 +0100 Subject: [PATCH 6/7] Update book/src/languages.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Blaž Hrastnik --- 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 3336a6135f8f..e45ef910a8d4 100644 --- a/book/src/languages.md +++ b/book/src/languages.md @@ -99,7 +99,7 @@ The `language-server` field takes the following keys: | `args` | A list of arguments to pass to the language server binary | | `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` | | `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 | -| `environment` | Any environment variables that will be used when starting the language server as an object { "Key1" = "Value1", "Key2" = "Value2" } | +| `environment` | Any environment variables that will be used when starting the language server `{ "KEY1" = "Value1", "KEY2" = "Value2" }` | The top-level `config` field is used to configure the LSP initialization options. A `format` sub-table within `config` can be used to pass extra formatting options to From da7d80780b01232852ccffeae5387b8caf5570a5 Mon Sep 17 00:00:00 2001 From: TotalKrill Date: Mon, 5 Dec 2022 10:00:22 +0100 Subject: [PATCH 7/7] Update helix-lsp/src/client.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Blaž Hrastnik --- helix-lsp/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 72629f754f24..9c74ab2bd859 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -47,7 +47,7 @@ impl Client { cmd: &str, args: &[String], config: Option, - server_environment: impl IntoIterator + Clone, + server_environment: HashMap, root_markers: &[String], id: usize, req_timeout: u64,