@@ -25,7 +25,7 @@ use project_model::{
2525use rustc_hash:: { FxHashMap , FxHashSet } ;
2626use tracing:: { span, Level } ;
2727use triomphe:: Arc ;
28- use vfs:: { AnchoredPathBuf , Vfs , VfsPath } ;
28+ use vfs:: { AnchoredPathBuf , ChangeKind , Vfs , VfsPath } ;
2929
3030use crate :: {
3131 config:: { Config , ConfigChange , ConfigErrors } ,
@@ -262,19 +262,9 @@ impl GlobalState {
262262 // that can be used by the config module because config talks
263263 // in `SourceRootId`s instead of `FileId`s and `FileId` -> `SourceRootId`
264264 // mapping is not ready until `AnalysisHost::apply_changes` has been called.
265- let mut modified_ratoml_files: FxHashMap < FileId , vfs:: VfsPath > = FxHashMap :: default ( ) ;
266- let mut ratoml_text_map: FxHashMap < FileId , ( vfs:: VfsPath , Option < String > ) > =
265+ let mut modified_ratoml_files: FxHashMap < FileId , ( ChangeKind , vfs:: VfsPath ) > =
267266 FxHashMap :: default ( ) ;
268267
269- let mut user_config_file: Option < Option < String > > = None ;
270- let mut root_path_ratoml: Option < Option < String > > = None ;
271-
272- let root_vfs_path = {
273- let mut root_vfs_path = self . config . root_path ( ) . to_path_buf ( ) ;
274- root_vfs_path. push ( "rust-analyzer.toml" ) ;
275- VfsPath :: new_real_path ( root_vfs_path. to_string ( ) )
276- } ;
277-
278268 let ( change, modified_rust_files, workspace_structure_change) = {
279269 let mut change = ChangeWithProcMacros :: new ( ) ;
280270 let mut guard = self . vfs . write ( ) ;
@@ -296,7 +286,7 @@ impl GlobalState {
296286 let vfs_path = vfs. file_path ( file. file_id ) ;
297287 if let Some ( ( "rust-analyzer" , Some ( "toml" ) ) ) = vfs_path. name_and_extension ( ) {
298288 // Remember ids to use them after `apply_changes`
299- modified_ratoml_files. insert ( file. file_id , vfs_path. clone ( ) ) ;
289+ modified_ratoml_files. insert ( file. file_id , ( file . kind ( ) , vfs_path. clone ( ) ) ) ;
300290 }
301291
302292 if let Some ( path) = vfs_path. as_path ( ) {
@@ -344,17 +334,7 @@ impl GlobalState {
344334 Some ( text)
345335 }
346336 } ;
347-
348- change. change_file ( file_id, text. clone ( ) ) ;
349- if let Some ( vfs_path) = modified_ratoml_files. get ( & file_id) {
350- if vfs_path == self . config . user_config_path ( ) {
351- user_config_file = Some ( text) ;
352- } else if vfs_path == & root_vfs_path {
353- root_path_ratoml = Some ( text) ;
354- } else {
355- ratoml_text_map. insert ( file_id, ( vfs_path. clone ( ) , text) ) ;
356- }
357- }
337+ change. change_file ( file_id, text) ;
358338 } ) ;
359339 if has_structure_changes {
360340 let roots = self . source_root_config . partition ( vfs) ;
@@ -365,22 +345,35 @@ impl GlobalState {
365345
366346 let _p = span ! ( Level :: INFO , "GlobalState::process_changes/apply_change" ) . entered ( ) ;
367347 self . analysis_host . apply_change ( change) ;
368- if !( ratoml_text_map. is_empty ( ) && user_config_file. is_none ( ) && root_path_ratoml. is_none ( ) )
369- {
348+ if !modified_ratoml_files. is_empty ( ) {
370349 let config_change = {
350+ let user_config_path = self . config . user_config_path ( ) ;
351+ let root_ratoml_path = self . config . root_ratoml_path ( ) ;
371352 let mut change = ConfigChange :: default ( ) ;
372353 let db = self . analysis_host . raw_database ( ) ;
373354
374- for ( file_id, ( vfs_path, text) ) in ratoml_text_map {
355+ for ( file_id, ( _change_kind, vfs_path) ) in modified_ratoml_files {
356+ if vfs_path == * user_config_path {
357+ change. change_user_config ( Some ( db. file_text ( file_id) ) ) ;
358+ continue ;
359+ }
360+
361+ if vfs_path == * root_ratoml_path {
362+ change. change_root_ratoml ( Some ( db. file_text ( file_id) ) ) ;
363+ continue ;
364+ }
365+
375366 // If change has been made to a ratoml file that
376367 // belongs to a non-local source root, we will ignore it.
377368 // As it doesn't make sense a users to use external config files.
378369 let sr_id = db. file_source_root ( file_id) ;
379370 let sr = db. source_root ( sr_id) ;
380371 if !sr. is_library {
381- if let Some ( ( old_path, old_text) ) =
382- change. change_ratoml ( sr_id, vfs_path. clone ( ) , text)
383- {
372+ if let Some ( ( old_path, old_text) ) = change. change_ratoml (
373+ sr_id,
374+ vfs_path. clone ( ) ,
375+ Some ( db. file_text ( file_id) ) ,
376+ ) {
384377 // SourceRoot has more than 1 RATOML files. In this case lexicographically smaller wins.
385378 if old_path < vfs_path {
386379 span ! ( Level :: ERROR , "Two `rust-analyzer.toml` files were found inside the same crate. {vfs_path} has no effect." ) ;
@@ -394,14 +387,6 @@ impl GlobalState {
394387 }
395388 }
396389
397- if let Some ( Some ( txt) ) = user_config_file {
398- change. change_user_config ( Some ( txt) ) ;
399- }
400-
401- if let Some ( Some ( txt) ) = root_path_ratoml {
402- change. change_root_ratoml ( Some ( txt) ) ;
403- }
404-
405390 change
406391 } ;
407392
0 commit comments