about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukas.wirth@ferrous-systems.com>2023-10-06 13:26:36 +0200
committerLukas Wirth <lukas.wirth@ferrous-systems.com>2023-10-06 13:26:36 +0200
commitb3ebc9ab6a0793612d75d3587f9de3522f6a71bb (patch)
tree762e8da4ecc9ec83fa262526ccce2776170a87a9
parenta8ec77dc7e30af115f542e137395e204b0fb5b28 (diff)
downloadrust-b3ebc9ab6a0793612d75d3587f9de3522f6a71bb.tar.gz
rust-b3ebc9ab6a0793612d75d3587f9de3522f6a71bb.zip
Check for both path separators on windows
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index 8dc0c97bc58..6c2f1ec3fed 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -2000,8 +2000,18 @@ fn run_rustfmt(
             let workspace = CargoTargetSpec::for_file(&snap, file_id)?;
             let mut cmd = match workspace {
                 Some(spec) => {
-                    let cmd = spec.workspace_root.join(cmd);
-                    process::Command::new(cmd.as_os_str())
+                    // approach: if the command name contains a path seperator, join it with the workspace root.
+                    // however, if the path is absolute, joining will result in the absolute path being preserved.
+                    // as a fallback, rely on $PATH-based discovery.
+                    let cmd_path =
+                        if cfg!(windows) && command.contains(&[std::path::MAIN_SEPARATOR, '/']) {
+                            spec.workspace_root.join(cmd).into()
+                        } else if command.contains(std::path::MAIN_SEPARATOR) {
+                            spec.workspace_root.join(cmd).into()
+                        } else {
+                            cmd
+                        };
+                    process::Command::new(cmd_path)
                 }
                 None => process::Command::new(cmd),
             };