Skip to content

Commit a8ec77d

Browse files
committed
address PR feedback.
1 parent 2974416 commit a8ec77d

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

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

+6-34
Original file line numberDiff line numberDiff line change
@@ -1997,41 +1997,13 @@ fn run_rustfmt(
19971997
}
19981998
RustfmtConfig::CustomCommand { command, args } => {
19991999
let cmd = PathBuf::from(&command);
2000-
let mut components = cmd.components();
2001-
2002-
// to support rustc's suggested, default configuration
2003-
let mut cmd = match components.next() {
2004-
Some(std::path::Component::CurDir) => {
2005-
let rest = components.as_path();
2006-
2007-
let roots = snap
2008-
.workspaces
2009-
.iter()
2010-
.flat_map(|ws| ws.workspace_definition_path())
2011-
.collect::<Vec<&AbsPath>>();
2012-
2013-
let abs: Option<AbsPathBuf> = roots.into_iter().find_map(|base| {
2014-
let abs = base.join(rest);
2015-
std::fs::metadata(&abs).ok().map(|_| abs)
2016-
});
2017-
2018-
let command = match abs {
2019-
Some(cmd) => cmd,
2020-
None => {
2021-
tracing::error!(
2022-
rustfmt = ?command,
2023-
"Unable to make the format command an absolute path"
2024-
);
2025-
anyhow::bail!(
2026-
"Unable to make the format command an absolute path: {}",
2027-
command
2028-
);
2029-
}
2030-
};
2031-
2032-
process::Command::new(&command.as_os_str())
2000+
let workspace = CargoTargetSpec::for_file(&snap, file_id)?;
2001+
let mut cmd = match workspace {
2002+
Some(spec) => {
2003+
let cmd = spec.workspace_root.join(cmd);
2004+
process::Command::new(cmd.as_os_str())
20332005
}
2034-
_ => process::Command::new(command),
2006+
None => process::Command::new(cmd),
20352007
};
20362008

20372009
cmd.envs(snap.config.extra_env());

0 commit comments

Comments
 (0)