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
This commit is contained in:
Conrad Irwin 2024-11-14 12:26:55 -07:00 committed by GitHub
parent 56c93be4de
commit 7f52071513
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 13 deletions

View file

@ -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"])

View file

@ -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)
})
}