From f3abd1dab551626a581f184776ff6a9ac86df203 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Fri, 3 Oct 2025 12:42:46 +0200 Subject: [PATCH] Fix rust-analyzer startup issue in single-file worktrees (#39441) I'm not sure about the exact conditions for reproducing this issue, but whenever I build Zed locally and have it open a single-file worktree on launch, the rust-analyzer language server fails to start up because Zed attempts to run `rust-analyzer --help` on a path that is not a directory. This fixes that by running the command on the parent path in the case of a single-file worktree. Release Notes: - Fixed rust-analyzer startup issue in single-file worktrees --- crates/project/src/lsp_store.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index c91547c230..998deb197f 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -12757,7 +12757,10 @@ impl LspAdapterDelegate for LocalLspAdapterDelegate { #[cfg(not(target_os = "windows"))] async fn which(&self, command: &OsStr) -> Option { - let worktree_abs_path = self.worktree.abs_path(); + let mut worktree_abs_path = self.worktree_root_path().to_path_buf(); + if self.fs.is_file(&worktree_abs_path).await { + worktree_abs_path.pop(); + } let shell_path = self.shell_env().await.get("PATH").cloned(); which::which_in(command, shell_path.as_ref(), worktree_abs_path).ok() } @@ -12771,7 +12774,10 @@ impl LspAdapterDelegate for LocalLspAdapterDelegate { } async fn try_exec(&self, command: LanguageServerBinary) -> Result<()> { - let working_dir = self.worktree_root_path(); + let mut working_dir = self.worktree_root_path().to_path_buf(); + if self.fs.is_file(&working_dir).await { + working_dir.pop(); + } let output = util::command::new_smol_command(&command.path) .args(command.arguments) .envs(command.env.clone().unwrap_or_default())