Unnamed repository; edit this file 'description' to name the repository.
address PR feedback.
David Barsky 2023-10-04
parent 2974416 · commit a8ec77d
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs40
1 files changed, 6 insertions, 34 deletions
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index ad6319586c..8dc0c97bc5 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -1997,41 +1997,13 @@ fn run_rustfmt(
}
RustfmtConfig::CustomCommand { command, args } => {
let cmd = PathBuf::from(&command);
- let mut components = cmd.components();
-
- // to support rustc's suggested, default configuration
- let mut cmd = match components.next() {
- Some(std::path::Component::CurDir) => {
- let rest = components.as_path();
-
- let roots = snap
- .workspaces
- .iter()
- .flat_map(|ws| ws.workspace_definition_path())
- .collect::<Vec<&AbsPath>>();
-
- let abs: Option<AbsPathBuf> = roots.into_iter().find_map(|base| {
- let abs = base.join(rest);
- std::fs::metadata(&abs).ok().map(|_| abs)
- });
-
- let command = match abs {
- Some(cmd) => cmd,
- None => {
- tracing::error!(
- rustfmt = ?command,
- "Unable to make the format command an absolute path"
- );
- anyhow::bail!(
- "Unable to make the format command an absolute path: {}",
- command
- );
- }
- };
-
- process::Command::new(&command.as_os_str())
+ 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())
}
- _ => process::Command::new(command),
+ None => process::Command::new(cmd),
};
cmd.envs(snap.config.extra_env());