Skip to content

Commit 2e98904

Browse files
committed
introduce a path-based discovery mechanism.
1 parent a8ec77d commit 2e98904

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,8 +2000,15 @@ 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 = if command.contains(std::path::MAIN_SEPARATOR_STR) {
2007+
spec.workspace_root.join(cmd).into()
2008+
} else {
2009+
cmd
2010+
};
2011+
process::Command::new(cmd_path)
20052012
}
20062013
None => process::Command::new(cmd),
20072014
};

0 commit comments

Comments
 (0)