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
This commit is contained in:
@@ -12757,7 +12757,10 @@ impl LspAdapterDelegate for LocalLspAdapterDelegate {
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
async fn which(&self, command: &OsStr) -> Option<PathBuf> {
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user