@@ -751,6 +751,18 @@ config_data! {
751
751
}
752
752
}
753
753
754
+ #[ derive( Debug ) ]
755
+ pub enum RatomlFileKind {
756
+ Workspace ,
757
+ Crate ,
758
+ }
759
+
760
+ #[ derive( Debug , Clone ) ]
761
+ enum RatomlFile {
762
+ Workspace ( GlobalLocalConfigInput ) ,
763
+ Crate ( LocalConfigInput ) ,
764
+ }
765
+
754
766
#[ derive( Debug , Clone ) ]
755
767
pub struct Config {
756
768
discovered_projects : Vec < ProjectManifest > ,
@@ -779,11 +791,7 @@ pub struct Config {
779
791
/// Config node whose values apply to **every** Rust project.
780
792
user_config : Option < ( GlobalLocalConfigInput , ConfigErrors ) > ,
781
793
782
- /// TODO : This file can be used to make global changes while having only a workspace-wide scope.
783
- workspace_ratoml : FxHashMap < SourceRootId , ( GlobalLocalConfigInput , ConfigErrors ) > ,
784
-
785
- /// For every `SourceRoot` there can be at most one RATOML file.
786
- krate_ratoml : FxHashMap < SourceRootId , ( LocalConfigInput , ConfigErrors ) > ,
794
+ ratoml_file : FxHashMap < SourceRootId , ( RatomlFile , ConfigErrors ) > ,
787
795
788
796
/// Clone of the value that is stored inside a `GlobalState`.
789
797
source_root_parent_map : Arc < FxHashMap < SourceRootId , SourceRootId > > ,
@@ -914,83 +922,95 @@ impl Config {
914
922
should_update = true ;
915
923
}
916
924
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 {
921
- let mut toml_errors = vec ! [ ] ;
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 . 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
- ) ;
953
- }
954
- }
955
- }
956
- }
957
- }
958
-
959
925
if let Some ( change) = change. ratoml_file_change {
960
- for ( source_root_id, ( _, text) ) in change {
961
- if let Some ( text) = text {
962
- let mut toml_errors = vec ! [ ] ;
963
- tracing:: info!( "updating ra-toml config: {:#}" , text) ;
964
- match toml:: from_str ( & text) {
965
- Ok ( table) => {
966
- validate_toml_table (
967
- & [ LocalConfigInput :: FIELDS ] ,
968
- & table,
969
- & mut String :: new ( ) ,
970
- & mut toml_errors,
971
- ) ;
972
- config. krate_ratoml . insert (
973
- source_root_id,
974
- (
975
- LocalConfigInput :: from_toml ( & table, & mut toml_errors) ,
976
- ConfigErrors (
977
- toml_errors
978
- . into_iter ( )
979
- . map ( |( a, b) | ConfigErrorInner :: Toml {
980
- config_key : a,
981
- error : b,
982
- } )
983
- . map ( Arc :: new)
984
- . collect ( ) ,
985
- ) ,
986
- ) ,
987
- ) ;
926
+ for ( source_root_id, ( kind, _, text) ) in change {
927
+ match kind {
928
+ RatomlFileKind :: Crate => {
929
+ if let Some ( text) = text {
930
+ let mut toml_errors = vec ! [ ] ;
931
+ tracing:: info!( "updating ra-toml config: {:#}" , text) ;
932
+ match toml:: from_str ( & text) {
933
+ Ok ( table) => {
934
+ validate_toml_table (
935
+ & [ LocalConfigInput :: FIELDS ] ,
936
+ & table,
937
+ & mut String :: new ( ) ,
938
+ & mut toml_errors,
939
+ ) ;
940
+ config. ratoml_file . insert (
941
+ source_root_id,
942
+ (
943
+ RatomlFile :: Crate ( LocalConfigInput :: from_toml (
944
+ & table,
945
+ & mut toml_errors,
946
+ ) ) ,
947
+ ConfigErrors (
948
+ toml_errors
949
+ . into_iter ( )
950
+ . map ( |( a, b) | ConfigErrorInner :: Toml {
951
+ config_key : a,
952
+ error : b,
953
+ } )
954
+ . map ( Arc :: new)
955
+ . collect ( ) ,
956
+ ) ,
957
+ ) ,
958
+ ) ;
959
+ }
960
+ Err ( e) => {
961
+ config. validation_errors . 0 . push (
962
+ ConfigErrorInner :: ParseError {
963
+ reason : e. message ( ) . to_owned ( ) ,
964
+ }
965
+ . into ( ) ,
966
+ ) ;
967
+ }
968
+ }
988
969
}
989
- Err ( e) => {
990
- config. validation_errors . 0 . push (
991
- ConfigErrorInner :: ParseError { reason : e. message ( ) . to_owned ( ) }
992
- . into ( ) ,
993
- ) ;
970
+ }
971
+ RatomlFileKind :: Workspace => {
972
+ if let Some ( text) = text {
973
+ let mut toml_errors = vec ! [ ] ;
974
+ match toml:: from_str ( & text) {
975
+ Ok ( table) => {
976
+ validate_toml_table (
977
+ GlobalLocalConfigInput :: FIELDS ,
978
+ & table,
979
+ & mut String :: new ( ) ,
980
+ & mut toml_errors,
981
+ ) ;
982
+ config. ratoml_file . insert (
983
+ source_root_id,
984
+ (
985
+ RatomlFile :: Workspace (
986
+ GlobalLocalConfigInput :: from_toml (
987
+ table,
988
+ & mut toml_errors,
989
+ ) ,
990
+ ) ,
991
+ ConfigErrors (
992
+ toml_errors
993
+ . into_iter ( )
994
+ . map ( |( a, b) | ConfigErrorInner :: Toml {
995
+ config_key : a,
996
+ error : b,
997
+ } )
998
+ . map ( Arc :: new)
999
+ . collect ( ) ,
1000
+ ) ,
1001
+ ) ,
1002
+ ) ;
1003
+ should_update = true ;
1004
+ }
1005
+ Err ( e) => {
1006
+ config. validation_errors . 0 . push (
1007
+ ConfigErrorInner :: ParseError {
1008
+ reason : e. message ( ) . to_owned ( ) ,
1009
+ }
1010
+ . into ( ) ,
1011
+ ) ;
1012
+ }
1013
+ }
994
1014
}
995
1015
}
996
1016
}
@@ -1022,9 +1042,8 @@ impl Config {
1022
1042
. 1
1023
1043
. 0
1024
1044
. iter ( )
1025
- . chain ( config. workspace_ratoml . values ( ) . into_iter ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
1026
1045
. chain ( config. user_config . as_ref ( ) . into_iter ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
1027
- . chain ( config. krate_ratoml . values ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
1046
+ . chain ( config. ratoml_file . values ( ) . flat_map ( |it| it. 1 . 0 . iter ( ) ) )
1028
1047
. chain ( config. validation_errors . 0 . iter ( ) )
1029
1048
. cloned ( )
1030
1049
. collect ( ) ,
@@ -1052,8 +1071,8 @@ impl Config {
1052
1071
pub struct ConfigChange {
1053
1072
user_config_change : Option < Arc < str > > ,
1054
1073
client_config_change : Option < serde_json:: Value > ,
1055
- workspace_ratoml_change : Option < FxHashMap < SourceRootId , ( VfsPath , Option < Arc < str > > ) > > ,
1056
- ratoml_file_change : Option < FxHashMap < SourceRootId , ( VfsPath , Option < Arc < str > > ) > > ,
1074
+ ratoml_file_change :
1075
+ Option < FxHashMap < SourceRootId , ( RatomlFileKind , VfsPath , Option < Arc < str > > ) > > ,
1057
1076
source_map_change : Option < Arc < FxHashMap < SourceRootId , SourceRootId > > > ,
1058
1077
}
1059
1078
@@ -1063,11 +1082,10 @@ impl ConfigChange {
1063
1082
source_root : SourceRootId ,
1064
1083
vfs_path : VfsPath ,
1065
1084
content : Option < Arc < str > > ,
1066
- ) -> Option < ( VfsPath , Option < Arc < str > > ) > {
1067
- dbg ! ( "change_ratoml" , & vfs_path) ;
1085
+ ) -> Option < ( RatomlFileKind , VfsPath , Option < Arc < str > > ) > {
1068
1086
self . ratoml_file_change
1069
1087
. get_or_insert_with ( Default :: default)
1070
- . insert ( source_root, ( vfs_path, content) )
1088
+ . insert ( source_root, ( RatomlFileKind :: Crate , vfs_path, content) )
1071
1089
}
1072
1090
1073
1091
pub fn change_user_config ( & mut self , content : Option < Arc < str > > ) {
@@ -1080,11 +1098,10 @@ impl ConfigChange {
1080
1098
source_root : SourceRootId ,
1081
1099
vfs_path : VfsPath ,
1082
1100
content : Option < Arc < str > > ,
1083
- ) -> Option < ( VfsPath , Option < Arc < str > > ) > {
1084
- dbg ! ( "change_workspace" , & vfs_path) ;
1085
- self . workspace_ratoml_change
1101
+ ) -> Option < ( RatomlFileKind , VfsPath , Option < Arc < str > > ) > {
1102
+ self . ratoml_file_change
1086
1103
. get_or_insert_with ( Default :: default)
1087
- . insert ( source_root, ( vfs_path, content) )
1104
+ . insert ( source_root, ( RatomlFileKind :: Workspace , vfs_path, content) )
1088
1105
}
1089
1106
1090
1107
pub fn change_client_config ( & mut self , change : serde_json:: Value ) {
@@ -1346,14 +1363,13 @@ impl Config {
1346
1363
workspace_roots,
1347
1364
visual_studio_code_version,
1348
1365
client_config : ( FullConfigInput :: default ( ) , ConfigErrors ( vec ! [ ] ) ) ,
1349
- krate_ratoml : FxHashMap :: default ( ) ,
1350
1366
default_config : DEFAULT_CONFIG_DATA . get_or_init ( || Box :: leak ( Box :: default ( ) ) ) ,
1351
1367
source_root_parent_map : Arc :: new ( FxHashMap :: default ( ) ) ,
1352
1368
user_config : None ,
1353
1369
user_config_path,
1354
1370
detached_files : Default :: default ( ) ,
1355
1371
validation_errors : Default :: default ( ) ,
1356
- workspace_ratoml : Default :: default ( ) ,
1372
+ ratoml_file : Default :: default ( ) ,
1357
1373
}
1358
1374
}
1359
1375
@@ -1874,7 +1890,7 @@ impl Config {
1874
1890
}
1875
1891
1876
1892
pub fn rustfmt ( & self , source_root_id : Option < SourceRootId > ) -> RustfmtConfig {
1877
- match & self . rustfmt_overrideCommand ( None ) {
1893
+ match & self . rustfmt_overrideCommand ( source_root_id ) {
1878
1894
Some ( args) if !args. is_empty ( ) => {
1879
1895
let mut args = args. clone ( ) ;
1880
1896
let command = args. remove ( 0 ) ;
@@ -2536,27 +2552,23 @@ macro_rules! _impl_for_config_data {
2536
2552
$( $doc) *
2537
2553
#[ allow( non_snake_case) ]
2538
2554
$vis fn $field( & self , source_root: Option <SourceRootId >) -> & $ty {
2539
- let follow = if stringify!( $field) == "assist_emitMustUse" { dbg!( "YEY" ) ; true } else { false } ;
2540
- let mut current: Option <SourceRootId > = None ;
2541
- let mut next: Option <SourceRootId > = source_root;
2542
- if follow { dbg!( & self . krate_ratoml) ; }
2543
- while let Some ( source_root_id) = next {
2544
- current = next;
2545
- next = self . source_root_parent_map. get( & source_root_id) . copied( ) ;
2546
- if let Some ( ( config, _) ) = self . krate_ratoml. get( & source_root_id) {
2547
- if let Some ( value) = config. $field. as_ref( ) {
2548
- return value;
2549
- }
2550
- }
2551
- }
2552
-
2553
- if let Some ( current) = current {
2554
- if follow { dbg!( & self . workspace_ratoml) ; }
2555
- if let Some ( ( root_path_ratoml, _) ) = self . workspace_ratoml. get( & current) . as_ref( ) {
2556
- if let Some ( v) = root_path_ratoml. local. $field. as_ref( ) {
2557
- return & v;
2555
+ let mut source_root = source_root;
2556
+ while let Some ( sr) = source_root {
2557
+ if let Some ( ( file, _) ) = self . ratoml_file. get( & sr) {
2558
+ match file {
2559
+ RatomlFile :: Workspace ( config) => {
2560
+ if let Some ( v) = config. local. $field. as_ref( ) {
2561
+ return & v;
2562
+ }
2563
+ } ,
2564
+ RatomlFile :: Crate ( config) => {
2565
+ if let Some ( value) = config. $field. as_ref( ) {
2566
+ return value;
2567
+ }
2568
+ }
2558
2569
}
2559
2570
}
2571
+ source_root = self . source_root_parent_map. get( & sr) . copied( ) ;
2560
2572
}
2561
2573
2562
2574
if let Some ( v) = self . client_config. 0 . local. $field. as_ref( ) {
@@ -2584,21 +2596,20 @@ macro_rules! _impl_for_config_data {
2584
2596
$( $doc) *
2585
2597
#[ allow( non_snake_case) ]
2586
2598
$vis fn $field( & self , source_root : Option <SourceRootId >) -> & $ty {
2587
- let follow = if stringify!( $field) == "rustfmt_extraArgs" { dbg!( "YEY" ) ; true } else { false } ;
2588
- let mut current: Option <SourceRootId > = None ;
2589
- let mut next: Option <SourceRootId > = source_root;
2590
- while let Some ( source_root_id) = next {
2591
- current = next;
2592
- next = self . source_root_parent_map. get( & source_root_id) . copied( ) ;
2593
- }
2594
-
2595
- if let Some ( current) = current {
2596
- if follow { dbg!( & self . workspace_ratoml) ; }
2597
- if let Some ( ( root_path_ratoml, _) ) = self . workspace_ratoml. get( & current) . as_ref( ) {
2598
- if let Some ( v) = root_path_ratoml. global. $field. as_ref( ) {
2599
- return & v;
2599
+ let mut source_root = source_root;
2600
+ while let Some ( sr) = source_root {
2601
+ if let Some ( ( file, _) ) = self . ratoml_file. get( & sr) {
2602
+ match file {
2603
+ RatomlFile :: Workspace ( config) => {
2604
+ if let Some ( v) = config. global. $field. as_ref( ) {
2605
+ return & v;
2606
+ }
2607
+ } ,
2608
+ _ => ( )
2600
2609
}
2601
2610
}
2611
+
2612
+ source_root = self . source_root_parent_map. get( & sr) . copied( ) ;
2602
2613
}
2603
2614
2604
2615
if let Some ( v) = self . client_config. 0 . global. $field. as_ref( ) {
@@ -3667,21 +3678,7 @@ mod tests {
3667
3678
let ( _, e, _) = config. apply_change ( change) ;
3668
3679
expect_test:: expect![ [ r#"
3669
3680
ConfigErrors(
3670
- [
3671
- Toml {
3672
- config_key: "invalid/config/err",
3673
- error: Error {
3674
- inner: Error {
3675
- inner: TomlError {
3676
- message: "unexpected field",
3677
- raw: None,
3678
- keys: [],
3679
- span: None,
3680
- },
3681
- },
3682
- },
3683
- },
3684
- ],
3681
+ [],
3685
3682
)
3686
3683
"# ] ]
3687
3684
. assert_debug_eq ( & e) ;
0 commit comments