File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -858,6 +858,23 @@ pub(crate) fn handle_formatting(
858
858
RustfmtConfig :: Rustfmt { extra_args } => {
859
859
let mut cmd = process:: Command :: new ( toolchain:: rustfmt ( ) ) ;
860
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
878
if let Some ( & crate_id) = crate_ids. first ( ) {
862
879
// Assume all crates are in the same edition
863
880
let edition = snap. analysis . crate_edition ( crate_id) ?;
You can’t perform that action at this time.
0 commit comments