DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/ExtensionManagement/
DefaultConfigurations.rs1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3use CommonLibrary::Error::CommonError::CommonError;
12use serde_json::{Map, Value};
13
14use crate::{ApplicationState::State::ApplicationState::ApplicationState, Environment::Utility};
15
16pub fn CollectDefaultConfigurations(State:&ApplicationState) -> Result<Value, CommonError> {
20 let mut MergedDefaults = Map::new();
21
22 let Extensions = State
23 .Extension
24 .ScannedExtensions
25 .ScannedExtensions
26 .lock()
27 .map_err(Utility::ErrorMapping::MapApplicationStateLockErrorToCommonError)?;
28
29 for Extension in Extensions.values() {
30 if let Some(contributes) = Extension.Contributes.as_ref().and_then(|v| v.as_object()) {
31 if let Some(configuration) = contributes.get("configuration").and_then(|v| v.as_object()) {
32 if let Some(properties) = configuration.get("properties").and_then(|v| v.as_object()) {
33 process_configuration_properties(&mut MergedDefaults, "", properties, &mut Vec::new())?;
34 }
35 }
36 }
37 }
38
39 Ok(Value::Object(MergedDefaults))
40}
41
42pub fn process_configuration_properties(
48 merged_defaults:&mut Map<String, Value>,
49 current_path:&str,
50 properties:&Map<String, Value>,
51 visited_keys:&mut Vec<String>,
52) -> Result<(), CommonError> {
53 for (key, value) in properties {
54 let full_path = if current_path.is_empty() {
55 key.clone()
56 } else {
57 format!("{}.{}", current_path, key)
58 };
59
60 if visited_keys.contains(&full_path) {
61 return Err(CommonError::Unknown {
62 Description:format!("Circular reference detected in configuration properties: {}", full_path),
63 });
64 }
65
66 visited_keys.push(full_path.clone());
67
68 if let Some(prop_details) = value.as_object() {
69 if let Some(nested_properties) = prop_details.get("properties").and_then(|v| v.as_object()) {
70 process_configuration_properties(merged_defaults, &full_path, nested_properties, visited_keys)?;
71 } else if let Some(default_value) = prop_details.get("default") {
72 merged_defaults.insert(full_path.clone(), default_value.clone());
73 }
74 }
75
76 visited_keys.retain(|k| k != &full_path);
77 }
78
79 Ok(())
80}