@@ -429,7 +429,7 @@ fn parse_manifest_version(contents: String) -> Option<String> {
429
429
None
430
430
}
431
431
432
- fn process_version ( var : Sourced < String > , ws_folders : & HashMap < String , String > , workspace_name : & String ) -> Sourced < String > {
432
+ fn process_version ( var : Sourced < String > , ws_folders : & HashMap < String , String > , workspace_name : Option < & String > ) -> Sourced < String > {
433
433
let Some ( config_path) = var. sources . iter ( ) . next ( ) . map ( PathBuf :: from) else {
434
434
unreachable ! ( "Expected at least one source for sourced_path: {:?}" , var) ;
435
435
} ;
@@ -624,7 +624,7 @@ pub fn default_profile_name() -> String {
624
624
"default" . to_string ( )
625
625
}
626
626
627
- fn fill_or_canonicalize < F > ( sourced_path : & Sourced < String > , ws_folders : & HashMap < String , String > , workspace_name : & String , predicate : & F , var_map : HashMap < String , String > ) -> Option < Sourced < String > >
627
+ fn fill_or_canonicalize < F > ( sourced_path : & Sourced < String > , ws_folders : & HashMap < String , String > , workspace_name : Option < & String > , predicate : & F , var_map : HashMap < String , String > ) -> Option < Sourced < String > >
628
628
where
629
629
F : Fn ( & String ) -> bool ,
630
630
{
@@ -651,7 +651,7 @@ F: Fn(&String) -> bool,
651
651
fn process_paths (
652
652
entry : & mut ConfigEntryRaw ,
653
653
ws_folders : & HashMap < String , String > ,
654
- workspace_name : & String ,
654
+ workspace_name : Option < & String > ,
655
655
) {
656
656
let var_map: HashMap < String , String > = match entry. version . clone ( ) {
657
657
Some ( v) => HashMap :: from ( [ ( S ! ( "version" ) , v. value ( ) . clone ( ) ) ] ) ,
@@ -901,8 +901,23 @@ fn merge_configs(
901
901
merged
902
902
}
903
903
904
+ fn load_config_from_file ( path : String , ws_folders : & HashMap < String , String > , ) -> Result < HashMap < String , ConfigEntryRaw > , String > {
905
+ let path = PathBuf :: from ( path) ;
906
+ if !path. exists ( ) || !path. is_file ( ) {
907
+ return Err ( S ! ( format!( "Config file not found: {}" , path. display( ) ) ) ) ;
908
+ }
909
+ process_config (
910
+ read_config_from_file ( path) ?,
911
+ ws_folders,
912
+ None ,
913
+ )
914
+ }
904
915
905
- fn load_merged_config_upward ( ws_folders : & HashMap < String , String > , workspace_name : & String , workspace_path : & String ) -> Result < HashMap < String , ConfigEntryRaw > , String > {
916
+ fn load_config_from_workspace (
917
+ ws_folders : & HashMap < String , String > ,
918
+ workspace_name : & String ,
919
+ workspace_path : & String ,
920
+ ) -> Result < HashMap < String , ConfigEntryRaw > , String > {
906
921
let mut current_dir = PathBuf :: from ( workspace_path) ;
907
922
let mut visited_dirs = HashSet :: new ( ) ;
908
923
let mut merged_config: HashMap < String , ConfigEntryRaw > = HashMap :: new ( ) ;
@@ -924,10 +939,29 @@ fn load_merged_config_upward(ws_folders: &HashMap<String, String>, workspace_nam
924
939
break ;
925
940
}
926
941
}
927
- apply_extends ( & mut merged_config) ?;
942
+ let mut merged_config = process_config ( merged_config, ws_folders, Some ( workspace_name) ) ?;
943
+
944
+ for entry in merged_config. values_mut ( ) {
945
+ if entry. abstract_ { continue ; }
946
+ if ( matches ! ( entry. add_workspace_addon_path. as_ref( ) . map( |a| a. value) , Some ( true ) ) || entry. addons_paths . is_none ( ) ) && is_addon_path ( workspace_path) {
947
+ let addon_path = Sourced { value : workspace_path. clone ( ) , sources : HashSet :: from ( [ S ! ( format!( "$workspaceFolder:{workspace_name}" ) ) ] ) , ..Default :: default ( ) } ;
948
+ match entry. addons_paths {
949
+ Some ( ref mut paths) => paths. push ( addon_path) ,
950
+ None => entry. addons_paths = Some ( vec ! [ addon_path] ) ,
951
+ }
952
+ }
953
+ }
954
+ Ok ( merged_config)
955
+ }
956
+
957
+ fn process_config (
958
+ mut config_map : HashMap < String , ConfigEntryRaw > ,
959
+ ws_folders : & HashMap < String , String > ,
960
+ workspace_name : Option < & String > ,
961
+ ) -> Result < HashMap < String , ConfigEntryRaw > , String > {
962
+ apply_extends ( & mut config_map) ?;
928
963
let mut new_configs = vec ! [ ] ;
929
- for config in merged_config. values_mut ( ) {
930
- // If the config has no odoo_path, try to infer it from workspace folders
964
+ for config in config_map. values_mut ( ) {
931
965
let Some ( version_var) = config. version . clone ( ) else {
932
966
continue ;
933
967
} ;
@@ -965,42 +999,31 @@ fn load_merged_config_upward(ws_folders: &HashMap<String, String>, workspace_nam
965
999
}
966
1000
}
967
1001
for new_entry in new_configs {
968
- merged_config . insert ( new_entry. name . clone ( ) , new_entry) ;
1002
+ config_map . insert ( new_entry. name . clone ( ) , new_entry) ;
969
1003
}
970
1004
971
1005
// Process vars
972
- merged_config . values_mut ( )
1006
+ config_map . values_mut ( )
973
1007
. for_each ( |entry| {
974
1008
// apply process_var to all vars
975
1009
if entry. abstract_ { return ; }
976
1010
entry. version = entry. version . clone ( ) . map ( |v| process_version ( v, ws_folders, workspace_name) ) ;
977
1011
} ) ;
978
1012
// Process paths in the merged config
979
- merged_config . values_mut ( )
1013
+ config_map . values_mut ( )
980
1014
. for_each ( |entry| {
981
1015
if entry. abstract_ { return ; }
982
1016
process_paths ( entry, ws_folders, workspace_name) ;
983
1017
} ) ;
984
1018
// Merge sourced paths
985
- merged_config . values_mut ( )
1019
+ config_map . values_mut ( )
986
1020
. for_each ( |entry| {
987
1021
if entry. abstract_ { return ; }
988
1022
entry. addons_paths = entry. addons_paths . clone ( ) . map ( |paths| group_sourced_iters ( paths) . collect ( ) ) ;
989
1023
entry. additional_stubs = entry. additional_stubs . clone ( ) . map ( |stubs| group_sourced_iters ( stubs) . collect ( ) ) ;
990
1024
} ) ;
991
1025
992
- for entry in merged_config. values_mut ( ) {
993
- if entry. abstract_ { continue ; }
994
- if ( matches ! ( entry. add_workspace_addon_path. as_ref( ) . map( |a| a. value) , Some ( true ) ) || entry. addons_paths . is_none ( ) ) && is_addon_path ( workspace_path) {
995
- let addon_path = Sourced { value : workspace_path. clone ( ) , sources : HashSet :: from ( [ S ! ( format!( "$workspaceFolder:{workspace_name}" ) ) ] ) , ..Default :: default ( ) } ;
996
- match entry. addons_paths {
997
- Some ( ref mut paths) => paths. push ( addon_path) ,
998
- None => entry. addons_paths = Some ( vec ! [ addon_path] ) ,
999
- }
1000
- }
1001
- }
1002
-
1003
- Ok ( merged_config)
1026
+ Ok ( config_map)
1004
1027
}
1005
1028
1006
1029
fn merge_all_workspaces (
@@ -1130,9 +1153,22 @@ fn merge_all_workspaces(
1130
1153
Ok ( ( final_config, config_file) )
1131
1154
}
1132
1155
1133
- pub fn get_configuration ( ws_folders : & HashMap < String , String > ) -> Result < ( ConfigNew , ConfigFile ) , String > {
1134
- let ws_confs: Result < Vec < _ > , _ > = ws_folders. iter ( ) . map ( |ws_f| load_merged_config_upward ( ws_folders, ws_f. 0 , ws_f. 1 ) ) . collect ( ) ;
1135
- merge_all_workspaces ( ws_confs?, ws_folders)
1156
+ pub fn get_configuration ( ws_folders : & HashMap < String , String > , cli_config_file : & Option < String > ) -> Result < ( ConfigNew , ConfigFile ) , String > {
1157
+ let mut ws_confs: Vec < HashMap < String , ConfigEntryRaw > > = Vec :: new ( ) ;
1158
+
1159
+ if let Some ( ref path) = cli_config_file {
1160
+ let config_from_file = load_config_from_file ( path. clone ( ) , ws_folders) ?;
1161
+ ws_confs. push ( config_from_file) ;
1162
+ }
1163
+
1164
+ let ws_confs_result: Result < Vec < _ > , _ > = ws_folders
1165
+ . iter ( )
1166
+ . map ( |ws_f| load_config_from_workspace ( ws_folders, ws_f. 0 , ws_f. 1 ) )
1167
+ . collect ( ) ;
1168
+
1169
+ ws_confs. extend ( ws_confs_result?) ;
1170
+
1171
+ merge_all_workspaces ( ws_confs, ws_folders)
1136
1172
}
1137
1173
1138
1174
/// Check if the old and new configuration entries are different enough to require a restart.
0 commit comments