address PR feedback.
This commit is contained in:
parent
2974416a81
commit
a8ec77dc7e
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user