@@ -2348,21 +2348,9 @@ fn run_rustfmt(
23482348 let file_id = try_default ! ( from_proto:: file_id( snap, & text_document. uri) ?) ;
23492349 let file = snap. analysis . file_text ( file_id) ?;
23502350
2351- // Determine the edition of the crate the file belongs to (if there's multiple, we pick the
2352- // highest edition).
2353- let Ok ( editions) = snap
2354- . analysis
2355- . relevant_crates_for ( file_id) ?
2356- . into_iter ( )
2357- . map ( |crate_id| snap. analysis . crate_edition ( crate_id) )
2358- . collect :: < Result < Vec < _ > , _ > > ( )
2359- else {
2360- return Ok ( None ) ;
2361- } ;
2362- let edition = editions. iter ( ) . copied ( ) . max ( ) ;
2363-
23642351 let line_index = snap. file_line_index ( file_id) ?;
23652352 let source_root_id = snap. analysis . source_root_id ( file_id) . ok ( ) ;
2353+ let crates = snap. analysis . relevant_crates_for ( file_id) ?;
23662354
23672355 // try to chdir to the file so we can respect `rustfmt.toml`
23682356 // FIXME: use `rustfmt --config-path` once
@@ -2383,6 +2371,17 @@ fn run_rustfmt(
23832371
23842372 let mut command = match snap. config . rustfmt ( source_root_id) {
23852373 RustfmtConfig :: Rustfmt { extra_args, enable_range_formatting } => {
2374+ // Determine the edition of the crate the file belongs to (if there's multiple, we pick the
2375+ // highest edition).
2376+ let Ok ( editions) = crates
2377+ . iter ( )
2378+ . map ( |& crate_id| snap. analysis . crate_edition ( crate_id) )
2379+ . collect :: < Result < Vec < _ > , _ > > ( )
2380+ else {
2381+ return Ok ( None ) ;
2382+ } ;
2383+ let edition = editions. iter ( ) . copied ( ) . max ( ) ;
2384+
23862385 // FIXME: Set RUSTUP_TOOLCHAIN
23872386 let mut cmd = toolchain:: command (
23882387 toolchain:: Tool :: Rustfmt . path ( ) ,
@@ -2429,7 +2428,8 @@ fn run_rustfmt(
24292428 }
24302429 RustfmtConfig :: CustomCommand { command, args } => {
24312430 let cmd = Utf8PathBuf :: from ( & command) ;
2432- let target_spec = TargetSpec :: for_file ( snap, file_id) ?;
2431+ let target_spec =
2432+ crates. first ( ) . and_then ( |& crate_id| snap. target_spec_for_file ( file_id, crate_id) ) ;
24332433 let extra_env = snap. config . extra_env ( source_root_id) ;
24342434 let mut cmd = match target_spec {
24352435 Some ( TargetSpec :: Cargo ( _) ) => {
0 commit comments