diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 32c5bbb21b..2ecda7d869 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -19,10 +19,7 @@ use tempfile::NamedTempFile; use util::paths::PathWithPosition; #[cfg(any(target_os = "linux", target_os = "freebsd"))] -use { - std::io::IsTerminal, - util::{load_login_shell_environment, load_shell_from_passwd, ResultExt}, -}; +use std::io::IsTerminal; struct Detect; @@ -167,15 +164,24 @@ fn main() -> Result<()> { None }; - // On Linux, desktop entry uses `cli` to spawn `zed`, so we need to load env vars from the shell - // since it doesn't inherit env vars from the terminal. - #[cfg(any(target_os = "linux", target_os = "freebsd"))] - if !std::io::stdout().is_terminal() { - load_shell_from_passwd().log_err(); - load_login_shell_environment().log_err(); - } + let env = { + #[cfg(any(target_os = "linux", target_os = "freebsd"))] + { + // On Linux, the desktop entry uses `cli` to spawn `zed`. + // We need to handle env vars correctly since std::env::vars() may not contain + // project-specific vars (e.g. those set by direnv). + // By setting env to None here, the LSP will use worktree env vars instead, + // which is what we want. + if !std::io::stdout().is_terminal() { + None + } else { + Some(std::env::vars().collect::>()) + } + } - let env = Some(std::env::vars().collect::>()); + #[cfg(not(any(target_os = "linux", target_os = "freebsd")))] + Some(std::env::vars().collect::>()) + }; let exit_status = Arc::new(Mutex::new(None)); let mut paths = vec![];