Skip to content

Commit 96d667b

Browse files
committed
fix: Join rustfmt overrideCommand with project root
When providing a custom rustfmt command, join it with the project root instead of the workspace root. This fixes rust-analyzer getting the wrong invocation path in projects containing subprojects. This makes the behaviour consistent with how a custom path provided in rust-analyzer.procMacro.server behaves already. Resolves issue rust-lang#18222
1 parent b91eeae commit 96d667b

File tree

1 file changed

+3
-3
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src/handlers

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,14 +2201,14 @@ fn run_rustfmt(
22012201
let cmd = Utf8PathBuf::from(&command);
22022202
let target_spec = TargetSpec::for_file(snap, file_id)?;
22032203
let mut cmd = match target_spec {
2204-
Some(TargetSpec::Cargo(spec)) => {
2205-
// approach: if the command name contains a path separator, join it with the workspace root.
2204+
Some(TargetSpec::Cargo(_)) => {
2205+
// approach: if the command name contains a path separator, join it with the project root.
22062206
// however, if the path is absolute, joining will result in the absolute path being preserved.
22072207
// as a fallback, rely on $PATH-based discovery.
22082208
let cmd_path = if command.contains(std::path::MAIN_SEPARATOR)
22092209
|| (cfg!(windows) && command.contains('/'))
22102210
{
2211-
spec.workspace_root.join(cmd).into()
2211+
snap.config.root_path().join(cmd).into()
22122212
} else {
22132213
cmd
22142214
};

0 commit comments

Comments
 (0)