Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

linux: Fix issue with project-specific env not being found via .envrc (direnv) (#22803)

tims632372a4f1a6
diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs
index 32c5bbb21be..2ecda7d8696 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::<HashMap<_, _>>())
+ }
+ }
- let env = Some(std::env::vars().collect::<HashMap<_, _>>());
+ #[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
+ Some(std::env::vars().collect::<HashMap<_, _>>())
+ };
let exit_status = Arc::new(Mutex::new(None));
let mut paths = vec![];