Common/Configuration/
InspectConfiguration.rs

1// File: Common/Source/Configuration/InspectConfiguration.rs
2// Role: Defines the `InspectConfiguration` ActionEffect.
3// Responsibilities:
4//   - Provide a declarative effect for inspecting a configuration's value
5//     across all its sources.
6//   - This effect abstracts the "what" (inspect a configuration) from the "how"
7//     (the ConfigurationInspector implementation).
8
9use std::sync::Arc;
10
11use serde_json::Value;
12
13use super::{
14	ConfigurationInspector::ConfigurationInspector,
15	DTO::{ConfigurationOverridesDTO::ConfigurationOverridesDTO, InspectResultDataDTO::InspectResultDataDTO},
16};
17use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
18
19/// Creates an effect that, when executed, will inspect a configuration key to
20/// get its value from all relevant sources (e.g., default, user, workspace).
21///
22/// It uses the `ConfigurationInspector` capability from the environment to
23/// perform the operation.
24///
25/// # Parameters
26///
27/// * `Key`: The dot-separated configuration key to inspect (e.g.,
28///   "Editor.FontSize").
29/// * `OverridesValue`: A `serde_json::Value` representing the
30///   `ConfigurationOverridesDTO`, which can specify a resource or language
31///   scope for the inspection.
32///
33/// # Returns
34///
35/// An `ActionEffect` that resolves with an `Option<InspectResultDataDTO>`,
36/// containing the detailed breakdown of the configuration value from all
37/// scopes.
38pub fn InspectConfiguration(
39	Key:String,
40
41	OverridesValue:Value,
42) -> ActionEffect<Arc<dyn ConfigurationInspector>, CommonError, Option<InspectResultDataDTO>> {
43	ActionEffect::New(Arc::new(move |Inspector:Arc<dyn ConfigurationInspector>| {
44		let KeyClone = Key.clone();
45
46		let OverridesValueClone = OverridesValue.clone();
47
48		Box::pin(async move {
49			let OverridesParsed:ConfigurationOverridesDTO =
50				serde_json::from_value(OverridesValueClone).map_err(|Error| {
51					CommonError::InvalidArgument {
52						ArgumentName:"OverridesValue".to_string(),
53
54						Reason:format!("Failed to parse ConfigurationOverridesDTO: {}", Error),
55					}
56				})?;
57
58			Inspector.InspectConfigurationValue(KeyClone, OverridesParsed).await
59		})
60	}))
61}