aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-21 14:15:14 +0000
committerGitHub <[email protected]>2021-01-21 14:15:14 +0000
commitcde22aba1c2cf55251365807bcd7170a9d34441c (patch)
tree861ecbf56eb8e3596aeef5ce17dc5ed6bfbe50ba /crates
parent0045d7c6db0d9e1e5f88702249c90c096f1882d8 (diff)
parentc067ca505a5ca48e3bf97fe15501ad61e9a12b6a (diff)
Merge #7371
7371: Change directory before running rustfmt to respect rustfmt.toml r=matklad a=lnicola Fixes #6973 Co-authored-by: LaurenČ›iu Nicola <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/handlers.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 001f3a37d..42451cd2d 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -858,6 +858,23 @@ pub(crate) fn handle_formatting(
858 RustfmtConfig::Rustfmt { extra_args } => { 858 RustfmtConfig::Rustfmt { extra_args } => {
859 let mut cmd = process::Command::new(toolchain::rustfmt()); 859 let mut cmd = process::Command::new(toolchain::rustfmt());
860 cmd.args(extra_args); 860 cmd.args(extra_args);
861 // try to chdir to the file so we can respect `rustfmt.toml`
862 // FIXME: use `rustfmt --config-path` once
863 // https://github.com/rust-lang/rustfmt/issues/4660 gets fixed
864 match params.text_document.uri.to_file_path() {
865 Ok(mut path) => {
866 // pop off file name
867 if path.pop() && path.is_dir() {
868 cmd.current_dir(path);
869 }
870 }
871 Err(_) => {
872 log::error!(
873 "Unable to get file path for {}, rustfmt.toml might be ignored",
874 params.text_document.uri
875 );
876 }
877 }
861 if let Some(&crate_id) = crate_ids.first() { 878 if let Some(&crate_id) = crate_ids.first() {
862 // Assume all crates are in the same edition 879 // Assume all crates are in the same edition
863 let edition = snap.analysis.crate_edition(crate_id)?; 880 let edition = snap.analysis.crate_edition(crate_id)?;