From 3a1b1847c1113d24afc663d03778758241718b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Mon, 28 Jul 2025 22:00:26 +0800 Subject: [PATCH] Fix debugger on Windows (#35180) Closes #33429 Release Notes: - N/A --- crates/project/src/debugger/dap_store.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/project/src/debugger/dap_store.rs b/crates/project/src/debugger/dap_store.rs index d494088b13..6f834b5dc0 100644 --- a/crates/project/src/debugger/dap_store.rs +++ b/crates/project/src/debugger/dap_store.rs @@ -920,12 +920,22 @@ impl dap::adapters::DapDelegate for DapAdapterDelegate { self.console.unbounded_send(msg).ok(); } + #[cfg(not(target_os = "windows"))] async fn which(&self, command: &OsStr) -> Option { let worktree_abs_path = self.worktree.abs_path(); let shell_path = self.shell_env().await.get("PATH").cloned(); which::which_in(command, shell_path.as_ref(), worktree_abs_path).ok() } + #[cfg(target_os = "windows")] + async fn which(&self, command: &OsStr) -> Option { + // On Windows, `PATH` is handled differently from Unix. Windows generally expects users to modify the `PATH` themselves, + // and every program loads it directly from the system at startup. + // There's also no concept of a default shell on Windows, and you can't really retrieve one, so trying to get shell environment variables + // from a specific directory doesn’t make sense on Windows. + which::which(command).ok() + } + async fn shell_env(&self) -> HashMap { let task = self.load_shell_env_task.clone(); task.await.unwrap_or_default()