fix Zed go lsp error

前言 前段时间在使用 Zed 编辑器时,出现了 go lsp 启动错误,未能正确找到 go 语言的二进制文件。 本文将一步步从源代码分析修复 Zed 的 go lsp 启动错误。 步骤 从错误信息可以得知,具体的逻辑在 /crates/languages/src/go.rs#L76,可以看到是 delegate.which("go".as_ref()).await.is_none() 方法的返回值为 true,导致 go 语言的二进制文件未找到。 接下来寻找 which 方法的定义位置,可以看到是在 /crates/project/src/lsp_store.rs#L12758,这段代码实现了 LspAdapterDelegate trait 中的 which 方法,用于在系统中查找可执行文件的路径。 修改 which 方法,添加一些日志,以便更好地理解其执行过程。 async fn which(&self, command: &OsStr) -> Option<PathBuf> { 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(); // Debug output log::info!( "which() called for command: {:?}, worktree_abs_path: {:?}, shell_path: {:?}", command, worktree_abs_path, shell_path ); let result = which::which_in(command, shell_path.as_ref(), worktree_abs_path).ok(); log::info!("which() result for {:?}: {:?}", command, result); result } 重新编译运行 Zed,查看日志: ...

十月 20, 2025 · 3 分钟 · overstarry