diff options
| author | David Barsky <me@davidbarsky.com> | 2023-10-03 16:44:09 -0400 |
|---|---|---|
| committer | David Barsky <me@davidbarsky.com> | 2023-10-03 16:44:09 -0400 |
| commit | a8ec77dc7e30af115f542e137395e204b0fb5b28 (patch) | |
| tree | 6899679c85af169698417d1e5341e132487b6cea | |
| parent | 2974416a81a64d75e0dc1c394b75fecd96230713 (diff) | |
| download | rust-a8ec77dc7e30af115f542e137395e204b0fb5b28.tar.gz rust-a8ec77dc7e30af115f542e137395e204b0fb5b28.zip | |
address PR feedback.
| -rw-r--r-- | crates/rust-analyzer/src/handlers/request.rs | 40 |
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 ad6319586cf..8dc0c97bc58 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()); |
