Skip to content

Commit 342d9ed

Browse files
committed
Fix rustfmt relative custom command
When `rustfmt.overrideCommand` is a relative path, it's joined with the workspace root to make it an absolute path. Without this the command path can't be resolved, especially because rustfmt changes the cwd to make sure rustfmt.toml works correctly. Currently `run_rustfmt` only does this when it finds a `target_spec` using `target_spec_for_file` which only works for the root file of the target. This commit changes it to use `TargetSpec::from_file` which works for any file in the crate.
1 parent 64ddb54 commit 342d9ed

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,8 +2442,7 @@ fn run_rustfmt(
24422442
}
24432443
RustfmtConfig::CustomCommand { command, args } => {
24442444
let cmd = Utf8PathBuf::from(&command);
2445-
let target_spec =
2446-
crates.first().and_then(|&crate_id| snap.target_spec_for_file(file_id, crate_id));
2445+
let target_spec = TargetSpec::for_file(snap, file_id).ok().flatten();
24472446
let extra_env = snap.config.extra_env(source_root_id);
24482447
let mut cmd = match target_spec {
24492448
Some(TargetSpec::Cargo(_)) => {

0 commit comments

Comments
 (0)