From 7f52071513e4683be48c7eb0f69cad2cc7a6948a Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 14 Nov 2024 12:26:55 -0700 Subject: [PATCH] Use the project env when running LSPs (#20641) This change ensures we always run LSPs with the project environment (in addition to any overrides they provide). This helps ensure the environment is set correctly on remotes where we don't load the login shell environment and assign it to the current process. Also fixed the go language to use the project env to find the go command. Release Notes: - Improved environment variable handling for SSH remotes --- crates/languages/src/go.rs | 6 +++--- crates/project/src/lsp_store.rs | 13 +++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/crates/languages/src/go.rs b/crates/languages/src/go.rs index 8713495b3187a1cd21258733b5b5f76f82d56081..669f6918a9541febfc616108facc129ba0578408 100644 --- a/crates/languages/src/go.rs +++ b/crates/languages/src/go.rs @@ -89,8 +89,7 @@ impl super::LspAdapter for GoLspAdapter { let delegate = delegate.clone(); Some(cx.spawn(|cx| async move { - let install_output = process::Command::new("go").args(["version"]).output().await; - if install_output.is_err() { + if delegate.which("go".as_ref()).await.is_none() { if DID_SHOW_NOTIFICATION .compare_exchange(false, true, SeqCst, SeqCst) .is_ok() @@ -139,7 +138,8 @@ impl super::LspAdapter for GoLspAdapter { let gobin_dir = container_dir.join("gobin"); fs::create_dir_all(&gobin_dir).await?; - let install_output = process::Command::new("go") + let go = delegate.which("go".as_ref()).await.unwrap_or("go".into()); + let install_output = process::Command::new(go) .env("GO111MODULE", "on") .env("GOBIN", &gobin_dir) .args(["install", "golang.org/x/tools/gopls@latest"]) diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index 5f1f6a88add186a8558ec8c7e30b43b5fb216e7e..0723ba689bbfabd8e41cf3b4e3d8c2a5f3b8a11e 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -5540,16 +5540,9 @@ impl LspStore { binary.arguments = arguments.into_iter().map(Into::into).collect(); } - // If we do have a project environment (either by spawning a shell in in the project directory - // or by getting it from the CLI) and the language server command itself - // doesn't have an environment, then we use the project environment. - if binary.env.is_none() { - log::info!( - "using project environment for language server {:?}", - adapter.name() - ); - binary.env = Some(delegate.shell_env().await); - } + let mut shell_env = delegate.shell_env().await; + shell_env.extend(binary.env.unwrap_or_default()); + binary.env = Some(shell_env); Ok(binary) }) }