@@ -779,11 +779,8 @@ pub struct Config {
779
779
/// Config node whose values apply to **every** Rust project.
780
780
user_config : Option < ( GlobalLocalConfigInput , ConfigErrors ) > ,
781
781
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 ) > ,
787
784
788
785
/// For every `SourceRoot` there can be at most one RATOML file.
789
786
ratoml_files : FxHashMap < SourceRootId , ( LocalConfigInput , ConfigErrors ) > ,
@@ -917,38 +914,44 @@ impl Config {
917
914
should_update = true ;
918
915
}
919
916
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 {
925
921
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
+ ) ;
949
953
}
950
- . into( ) ] ) ,
951
- ) ) ;
954
+ }
952
955
}
953
956
}
954
957
}
@@ -958,7 +961,6 @@ impl Config {
958
961
if let Some ( text) = text {
959
962
let mut toml_errors = vec ! [ ] ;
960
963
tracing:: info!( "updating ra-toml config: {:#}" , text) ;
961
- #[ allow( clippy:: single_match) ]
962
964
match toml:: from_str ( & text) {
963
965
Ok ( table) => {
964
966
validate_toml_table (
@@ -985,16 +987,10 @@ impl Config {
985
987
) ;
986
988
}
987
989
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
+ ) ;
998
994
}
999
995
}
1000
996
}
@@ -1026,7 +1022,13 @@ impl Config {
1026
1022
. 1
1027
1023
. 0
1028
1024
. 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
+ )
1030
1032
. chain ( config. user_config . as_ref ( ) . into_iter ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
1031
1033
. chain ( config. ratoml_files . values ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
1032
1034
. chain ( config. validation_errors . 0 . iter ( ) )
@@ -1055,8 +1057,8 @@ impl Config {
1055
1057
#[ derive( Default , Debug ) ]
1056
1058
pub struct ConfigChange {
1057
1059
user_config_change : Option < Arc < str > > ,
1058
- root_ratoml_change : Option < Arc < str > > ,
1059
1060
client_config_change : Option < serde_json:: Value > ,
1061
+ workspace_ratoml_change : Option < FxHashMap < SourceRootId , ( VfsPath , Option < Arc < str > > ) > > ,
1060
1062
ratoml_file_change : Option < FxHashMap < SourceRootId , ( VfsPath , Option < Arc < str > > ) > > ,
1061
1063
source_map_change : Option < Arc < FxHashMap < SourceRootId , SourceRootId > > > ,
1062
1064
}
@@ -1078,9 +1080,15 @@ impl ConfigChange {
1078
1080
self . user_config_change = content;
1079
1081
}
1080
1082
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) )
1084
1092
}
1085
1093
1086
1094
pub fn change_client_config ( & mut self , change : serde_json:: Value ) {
@@ -1333,11 +1341,6 @@ impl Config {
1333
1341
// FIXME @alibektas : Temporary solution. I don't think this is right as at some point we may allow users to specify
1334
1342
// custom USER_CONFIG_PATHs which may also be relative.
1335
1343
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
- } ;
1341
1344
1342
1345
Config {
1343
1346
caps : ClientCapabilities :: new ( caps) ,
@@ -1352,10 +1355,9 @@ impl Config {
1352
1355
source_root_parent_map : Arc :: new ( FxHashMap :: default ( ) ) ,
1353
1356
user_config : None ,
1354
1357
user_config_path,
1355
- root_ratoml : None ,
1356
- root_ratoml_path,
1357
1358
detached_files : Default :: default ( ) ,
1358
1359
validation_errors : Default :: default ( ) ,
1360
+ workspace_ratoml_change : Default :: default ( ) ,
1359
1361
}
1360
1362
}
1361
1363
@@ -1398,10 +1400,6 @@ impl Config {
1398
1400
& self . root_path
1399
1401
}
1400
1402
1401
- pub fn root_ratoml_path ( & self ) -> & VfsPath {
1402
- & self . root_ratoml_path
1403
- }
1404
-
1405
1403
pub fn caps ( & self ) -> & ClientCapabilities {
1406
1404
& self . caps
1407
1405
}
@@ -3591,7 +3589,7 @@ mod tests {
3591
3589
3592
3590
let mut change = ConfigChange :: default ( ) ;
3593
3591
3594
- change. change_root_ratoml ( Some (
3592
+ change. change_user_config ( Some (
3595
3593
toml:: toml! {
3596
3594
[ cargo. cfgs]
3597
3595
these = "these"
0 commit comments