address PR feedback.
This commit is contained in:
parent
2974416a81
commit
a8ec77dc7e
@ -1997,41 +1997,13 @@ fn run_rustfmt(
|
|||||||
}
|
}
|
||||||
RustfmtConfig::CustomCommand { command, args } => {
|
RustfmtConfig::CustomCommand { command, args } => {
|
||||||
let cmd = PathBuf::from(&command);
|
let cmd = PathBuf::from(&command);
|
||||||
let mut components = cmd.components();
|
let workspace = CargoTargetSpec::for_file(&snap, file_id)?;
|
||||||
|
let mut cmd = match workspace {
|
||||||
// to support rustc's suggested, default configuration
|
Some(spec) => {
|
||||||
let mut cmd = match components.next() {
|
let cmd = spec.workspace_root.join(cmd);
|
||||||
Some(std::path::Component::CurDir) => {
|
process::Command::new(cmd.as_os_str())
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
_ => process::Command::new(command),
|
None => process::Command::new(cmd),
|
||||||
};
|
};
|
||||||
|
|
||||||
cmd.envs(snap.config.extra_env());
|
cmd.envs(snap.config.extra_env());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user