aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
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)?;