Skip to content

Commit b3ebc9a

Browse files
committed
Check for both path separators on windows
1 parent a8ec77d commit b3ebc9a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crates/rust-analyzer/src/handlers/request.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -2000,8 +2000,18 @@ fn run_rustfmt(
20002000
let workspace = CargoTargetSpec::for_file(&snap, file_id)?;
20012001
let mut cmd = match workspace {
20022002
Some(spec) => {
2003-
let cmd = spec.workspace_root.join(cmd);
2004-
process::Command::new(cmd.as_os_str())
2003+
// approach: if the command name contains a path seperator, join it with the workspace root.
2004+
// however, if the path is absolute, joining will result in the absolute path being preserved.
2005+
// as a fallback, rely on $PATH-based discovery.
2006+
let cmd_path =
2007+
if cfg!(windows) && command.contains(&[std::path::MAIN_SEPARATOR, '/']) {
2008+
spec.workspace_root.join(cmd).into()
2009+
} else if command.contains(std::path::MAIN_SEPARATOR) {
2010+
spec.workspace_root.join(cmd).into()
2011+
} else {
2012+
cmd
2013+
};
2014+
process::Command::new(cmd_path)
20052015
}
20062016
None => process::Command::new(cmd),
20072017
};

0 commit comments

Comments
 (0)