@@ -779,11 +779,8 @@ pub struct Config {
779779 /// Config node whose values apply to **every** Rust project.
780780 user_config : Option < ( GlobalLocalConfigInput , ConfigErrors ) > ,
781781
782- /// A special file for this session whose path is set to `self.root_path.join("rust-analyzer.toml")`
783- root_ratoml_path : VfsPath ,
784-
785- /// This file can be used to make global changes while having only a workspace-wide scope.
786- root_ratoml : Option < ( GlobalLocalConfigInput , ConfigErrors ) > ,
782+ /// TODO : This file can be used to make global changes while having only a workspace-wide scope.
783+ workspace_ratoml_change : FxHashMap < SourceRootId , ( GlobalLocalConfigInput , ConfigErrors ) > ,
787784
788785 /// For every `SourceRoot` there can be at most one RATOML file.
789786 ratoml_files : FxHashMap < SourceRootId , ( LocalConfigInput , ConfigErrors ) > ,
@@ -917,38 +914,44 @@ impl Config {
917914 should_update = true ;
918915 }
919916
920- if let Some ( change) = change. root_ratoml_change {
921- tracing:: info!( "updating root ra-toml config: {:#}" , change) ;
922- #[ allow( clippy:: single_match) ]
923- match toml:: from_str ( & change) {
924- Ok ( table) => {
917+ if let Some ( change) = change. workspace_ratoml_change {
918+ tracing:: info!( "updating root ra-toml config" ) ;
919+ for ( source_root_id, ( _, text) ) in change {
920+ if let Some ( text) = text {
925921 let mut toml_errors = vec ! [ ] ;
926- validate_toml_table (
927- GlobalLocalConfigInput :: FIELDS ,
928- & table,
929- & mut String :: new ( ) ,
930- & mut toml_errors,
931- ) ;
932- config. root_ratoml = Some ( (
933- GlobalLocalConfigInput :: from_toml ( table, & mut toml_errors) ,
934- ConfigErrors (
935- toml_errors
936- . into_iter ( )
937- . map ( |( a, b) | ConfigErrorInner :: Toml { config_key : a, error : b } )
938- . map ( Arc :: new)
939- . collect ( ) ,
940- ) ,
941- ) ) ;
942- should_update = true ;
943- }
944- Err ( e) => {
945- config. root_ratoml = Some ( (
946- GlobalLocalConfigInput :: from_toml ( toml:: map:: Map :: default ( ) , & mut vec ! [ ] ) ,
947- ConfigErrors ( vec ! [ ConfigErrorInner :: ParseError {
948- reason: e. message( ) . to_owned( ) ,
922+ match toml:: from_str ( & text) {
923+ Ok ( table) => {
924+ validate_toml_table (
925+ GlobalLocalConfigInput :: FIELDS ,
926+ & table,
927+ & mut String :: new ( ) ,
928+ & mut toml_errors,
929+ ) ;
930+ config. workspace_ratoml_change . insert (
931+ source_root_id,
932+ (
933+ GlobalLocalConfigInput :: from_toml ( table, & mut toml_errors) ,
934+ ConfigErrors (
935+ toml_errors
936+ . into_iter ( )
937+ . map ( |( a, b) | ConfigErrorInner :: Toml {
938+ config_key : a,
939+ error : b,
940+ } )
941+ . map ( Arc :: new)
942+ . collect ( ) ,
943+ ) ,
944+ ) ,
945+ ) ;
946+ should_update = true ;
947+ }
948+ Err ( e) => {
949+ config. validation_errors . 0 . push (
950+ ConfigErrorInner :: ParseError { reason : e. message ( ) . to_owned ( ) }
951+ . into ( ) ,
952+ ) ;
949953 }
950- . into( ) ] ) ,
951- ) ) ;
954+ }
952955 }
953956 }
954957 }
@@ -958,7 +961,6 @@ impl Config {
958961 if let Some ( text) = text {
959962 let mut toml_errors = vec ! [ ] ;
960963 tracing:: info!( "updating ra-toml config: {:#}" , text) ;
961- #[ allow( clippy:: single_match) ]
962964 match toml:: from_str ( & text) {
963965 Ok ( table) => {
964966 validate_toml_table (
@@ -985,16 +987,10 @@ impl Config {
985987 ) ;
986988 }
987989 Err ( e) => {
988- config. root_ratoml = Some ( (
989- GlobalLocalConfigInput :: from_toml (
990- toml:: map:: Map :: default ( ) ,
991- & mut vec ! [ ] ,
992- ) ,
993- ConfigErrors ( vec ! [ ConfigErrorInner :: ParseError {
994- reason: e. message( ) . to_owned( ) ,
995- }
996- . into( ) ] ) ,
997- ) ) ;
990+ config. validation_errors . 0 . push (
991+ ConfigErrorInner :: ParseError { reason : e. message ( ) . to_owned ( ) }
992+ . into ( ) ,
993+ ) ;
998994 }
999995 }
1000996 }
@@ -1026,7 +1022,13 @@ impl Config {
10261022 . 1
10271023 . 0
10281024 . iter ( )
1029- . chain ( config. root_ratoml . as_ref ( ) . into_iter ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
1025+ . chain (
1026+ config
1027+ . workspace_ratoml_change
1028+ . values ( )
1029+ . into_iter ( )
1030+ . flat_map ( |it| it. 1 . 0 . iter ( ) ) ,
1031+ )
10301032 . chain ( config. user_config . as_ref ( ) . into_iter ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
10311033 . chain ( config. ratoml_files . values ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
10321034 . chain ( config. validation_errors . 0 . iter ( ) )
@@ -1055,8 +1057,8 @@ impl Config {
10551057#[ derive( Default , Debug ) ]
10561058pub struct ConfigChange {
10571059 user_config_change : Option < Arc < str > > ,
1058- root_ratoml_change : Option < Arc < str > > ,
10591060 client_config_change : Option < serde_json:: Value > ,
1061+ workspace_ratoml_change : Option < FxHashMap < SourceRootId , ( VfsPath , Option < Arc < str > > ) > > ,
10601062 ratoml_file_change : Option < FxHashMap < SourceRootId , ( VfsPath , Option < Arc < str > > ) > > ,
10611063 source_map_change : Option < Arc < FxHashMap < SourceRootId , SourceRootId > > > ,
10621064}
@@ -1078,9 +1080,15 @@ impl ConfigChange {
10781080 self . user_config_change = content;
10791081 }
10801082
1081- pub fn change_root_ratoml ( & mut self , content : Option < Arc < str > > ) {
1082- assert ! ( self . root_ratoml_change. is_none( ) ) ; // Otherwise it is a double write.
1083- self . root_ratoml_change = content;
1083+ pub fn change_workspace_ratoml (
1084+ & mut self ,
1085+ source_root : SourceRootId ,
1086+ vfs_path : VfsPath ,
1087+ content : Option < Arc < str > > ,
1088+ ) -> Option < ( VfsPath , Option < Arc < str > > ) > {
1089+ self . workspace_ratoml_change
1090+ . get_or_insert_with ( Default :: default)
1091+ . insert ( source_root, ( vfs_path, content) )
10841092 }
10851093
10861094 pub fn change_client_config ( & mut self , change : serde_json:: Value ) {
@@ -1333,11 +1341,6 @@ impl Config {
13331341 // FIXME @alibektas : Temporary solution. I don't think this is right as at some point we may allow users to specify
13341342 // custom USER_CONFIG_PATHs which may also be relative.
13351343 let user_config_path = VfsPath :: from ( AbsPathBuf :: assert ( user_config_path) ) ;
1336- let root_ratoml_path = {
1337- let mut p = root_path. clone ( ) ;
1338- p. push ( "rust-analyzer.toml" ) ;
1339- VfsPath :: new_real_path ( p. to_string ( ) )
1340- } ;
13411344
13421345 Config {
13431346 caps : ClientCapabilities :: new ( caps) ,
@@ -1352,10 +1355,9 @@ impl Config {
13521355 source_root_parent_map : Arc :: new ( FxHashMap :: default ( ) ) ,
13531356 user_config : None ,
13541357 user_config_path,
1355- root_ratoml : None ,
1356- root_ratoml_path,
13571358 detached_files : Default :: default ( ) ,
13581359 validation_errors : Default :: default ( ) ,
1360+ workspace_ratoml_change : Default :: default ( ) ,
13591361 }
13601362 }
13611363
@@ -1398,10 +1400,6 @@ impl Config {
13981400 & self . root_path
13991401 }
14001402
1401- pub fn root_ratoml_path ( & self ) -> & VfsPath {
1402- & self . root_ratoml_path
1403- }
1404-
14051403 pub fn caps ( & self ) -> & ClientCapabilities {
14061404 & self . caps
14071405 }
@@ -3591,7 +3589,7 @@ mod tests {
35913589
35923590 let mut change = ConfigChange :: default ( ) ;
35933591
3594- change. change_root_ratoml ( Some (
3592+ change. change_user_config ( Some (
35953593 toml:: toml! {
35963594 [ cargo. cfgs]
35973595 these = "these"
0 commit comments