mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Merge #7371
7371: Change directory before running rustfmt to respect rustfmt.toml r=matklad a=lnicola Fixes #6973 Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
cde22aba1c
@ -858,6 +858,23 @@ pub(crate) fn handle_formatting(
|
|||||||
RustfmtConfig::Rustfmt { extra_args } => {
|
RustfmtConfig::Rustfmt { extra_args } => {
|
||||||
let mut cmd = process::Command::new(toolchain::rustfmt());
|
let mut cmd = process::Command::new(toolchain::rustfmt());
|
||||||
cmd.args(extra_args);
|
cmd.args(extra_args);
|
||||||
|
// try to chdir to the file so we can respect `rustfmt.toml`
|
||||||
|
// FIXME: use `rustfmt --config-path` once
|
||||||
|
// https://github.com/rust-lang/rustfmt/issues/4660 gets fixed
|
||||||
|
match params.text_document.uri.to_file_path() {
|
||||||
|
Ok(mut path) => {
|
||||||
|
// pop off file name
|
||||||
|
if path.pop() && path.is_dir() {
|
||||||
|
cmd.current_dir(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
log::error!(
|
||||||
|
"Unable to get file path for {}, rustfmt.toml might be ignored",
|
||||||
|
params.text_document.uri
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(&crate_id) = crate_ids.first() {
|
if let Some(&crate_id) = crate_ids.first() {
|
||||||
// Assume all crates are in the same edition
|
// Assume all crates are in the same edition
|
||||||
let edition = snap.analysis.crate_edition(crate_id)?;
|
let edition = snap.analysis.crate_edition(crate_id)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user