Skip to content

Commit 5df723e

Browse files
Re-Sync
1 parent 0ef40ca commit 5df723e

File tree

148 files changed

+5334
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+5334
-0
lines changed

Source/command/CommandExecutor.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use async_trait::async_trait;
2+
use serde_json::Value;
3+
4+
/// @module CommandExecutor
5+
/// @description Defines the abstract service trait for command management
6+
/// capabilities.
7+
use crate::environment::Environment;
8+
use crate::error::CommonError;
9+
10+
/// An abstract service contract for an environment component that can execute
11+
/// and manage commands within the application.
12+
///
13+
/// This trait is implemented by `MountainEnvironment` and provides the core
14+
/// logic for the command palette and programmatic command execution. It can
15+
/// handle both native commands implemented in Rust and proxied commands
16+
/// implemented in sidecars.
17+
#[async_trait]
18+
pub trait CommandExecutor: Environment + Send + Sync {
19+
/// Executes a command with the given ID and arguments.
20+
///
21+
/// @param CommandIdentifier - The unique ID of the command to execute.
22+
/// @param Argument - A `serde_json::Value` containing the arguments for
23+
/// the command. @returns A `Result` containing the command's return value
24+
/// as a `serde_json::Value`.
25+
async fn ExecuteCommand(&self, CommandIdentifier:String, Argument:Value) -> Result<Value, CommonError>;
26+
27+
/// Registers a command that is implemented in an external sidecar process.
28+
///
29+
/// @param SidecarIdentifier - The ID of the sidecar where the command logic
30+
/// resides. @param CommandIdentifier - The unique ID of the command being
31+
/// registered.
32+
async fn RegisterCommand(&self, SidecarIdentifier:String, CommandIdentifier:String) -> Result<(), CommonError>;
33+
34+
/// Unregisters a previously registered command.
35+
async fn UnregisterCommand(&self, SidecarIdentifier:String, CommandIdentifier:String) -> Result<(), CommonError>;
36+
37+
/// Retrieves a list of all currently registered command IDs.
38+
async fn GetAllCommands(&self) -> Result<Vec<String>, CommonError>;
39+
}

Source/command/ExecuteCommand.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::sync::Arc;
2+
3+
use serde_json::Value;
4+
5+
/// @module ExecuteCommand
6+
/// @description Defines the ActionEffect for executing a command.
7+
use super::CommandExecutor::CommandExecutor;
8+
use crate::{
9+
effect::{ActionEffect, AppRuntime},
10+
environment::Requires,
11+
error::CommonError,
12+
};
13+
14+
/// Creates an effect that, when executed, will run a command by its unique ID.
15+
///
16+
/// It uses the `CommandExecutor` capability from the environment to dispatch
17+
/// the command to the appropriate handler, whether native or proxied.
18+
///
19+
/// @param CommandIdentifier - The unique ID of the command to execute.
20+
/// @param Argument - A `serde_json::Value` containing the arguments for the
21+
/// command.
22+
///
23+
/// @returns An `ActionEffect` that resolves with the command's return value as
24+
/// a `serde_json::Value`.
25+
pub fn ExecuteCommand<Runtime>(
26+
CommandIdentifier:String,
27+
Argument:Value,
28+
) -> ActionEffect<Arc<Runtime>, CommonError, Value>
29+
where
30+
Runtime: AppRuntime + Send + Sync + 'static,
31+
Runtime::EnvironmentType: Requires<Arc<dyn CommandExecutor>>, {
32+
ActionEffect::New(Arc::new(move |Runtime:Arc<Runtime>| {
33+
let CommandIdentifierClone = CommandIdentifier.clone();
34+
let ArgumentClone = Argument.clone();
35+
Box::pin(async move {
36+
let Environment = Runtime.GetEnvironment();
37+
let Executor:Arc<dyn CommandExecutor> = Environment.Require();
38+
Executor.ExecuteCommand(CommandIdentifierClone, ArgumentClone).await
39+
})
40+
}))
41+
}

Source/command/GetAllCommands.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::sync::Arc;
2+
3+
/// @module GetAllCommands
4+
/// @description Defines the ActionEffect for retrieving all registered command
5+
/// IDs.
6+
use super::CommandExecutor::CommandExecutor;
7+
use crate::{
8+
effect::{ActionEffect, AppRuntime},
9+
environment::Requires,
10+
error::CommonError,
11+
};
12+
13+
/// Creates an effect that, when executed, will retrieve a list of all currently
14+
/// registered command identifiers, including both native and proxied commands.
15+
///
16+
/// It uses the `CommandExecutor` capability from the environment to perform the
17+
/// operation.
18+
///
19+
/// @returns An `ActionEffect` that resolves with a `Vec<String>` of command
20+
/// IDs.
21+
pub fn GetAllCommands<Runtime>() -> ActionEffect<Arc<Runtime>, CommonError, Vec<String>>
22+
where
23+
Runtime: AppRuntime + Send + Sync + 'static,
24+
Runtime::EnvironmentType: Requires<Arc<dyn CommandExecutor>>, {
25+
ActionEffect::New(Arc::new(move |Runtime:Arc<Runtime>| {
26+
Box::pin(async move {
27+
let Environment = Runtime.GetEnvironment();
28+
let Executor:Arc<dyn CommandExecutor> = Environment.Require();
29+
Executor.GetAllCommands().await
30+
})
31+
}))
32+
}

Source/command/RegisterCommand.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::sync::Arc;
2+
3+
/// @module RegisterCommand
4+
/// @description Defines the ActionEffect for registering a command that is
5+
/// implemented in an external sidecar process.
6+
use super::CommandExecutor::CommandExecutor;
7+
use crate::{
8+
effect::{ActionEffect, AppRuntime},
9+
environment::Requires,
10+
error::CommonError,
11+
};
12+
13+
/// Creates an effect that, when executed, will register a command that is
14+
/// implemented in a sidecar process like Cocoon.
15+
///
16+
/// This allows the host application (`Mountain`) to know about commands
17+
/// contributed by extensions so they can be displayed in the command palette
18+
/// and invoked correctly. The `CommandExecutor` implementation will store this
19+
/// as a `Proxied` command.
20+
///
21+
/// @param SidecarIdentifier - The unique ID of the sidecar where the command
22+
/// logic resides. @param CommandIdentifier - The unique ID of the command
23+
/// itself (e.g., "myExtension.doSomething").
24+
///
25+
/// @returns An `ActionEffect` that resolves to `()` on success.
26+
pub fn RegisterCommand<Runtime>(
27+
SidecarIdentifier:String,
28+
CommandIdentifier:String,
29+
) -> ActionEffect<Arc<Runtime>, CommonError, ()>
30+
where
31+
Runtime: AppRuntime + Send + Sync + 'static,
32+
Runtime::EnvironmentType: Requires<Arc<dyn CommandExecutor>>, {
33+
ActionEffect::New(Arc::new(move |Runtime:Arc<Runtime>| {
34+
let SidecarIdentifierClone = SidecarIdentifier.clone();
35+
let CommandIdentifierClone = CommandIdentifier.clone();
36+
Box::pin(async move {
37+
let Environment = Runtime.GetEnvironment();
38+
let Executor:Arc<dyn CommandExecutor> = Environment.Require();
39+
Executor.RegisterCommand(SidecarIdentifierClone, CommandIdentifierClone).await
40+
})
41+
}))
42+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::sync::Arc;
2+
3+
/// @module UnregisterCommand
4+
/// @description Defines the ActionEffect for unregistering a command.
5+
use super::CommandExecutor::CommandExecutor;
6+
use crate::{
7+
effect::{ActionEffect, AppRuntime},
8+
environment::Requires,
9+
error::CommonError,
10+
};
11+
12+
/// Creates an effect that, when executed, will unregister a command from the
13+
/// host's command registry.
14+
///
15+
/// This is typically called when an extension is deactivated or disposes of a
16+
/// command registration.
17+
///
18+
/// @param SidecarIdentifier - The unique ID of the sidecar that originally
19+
/// registered the command. @param CommandIdentifier - The unique ID of the
20+
/// command to unregister.
21+
///
22+
/// @returns An `ActionEffect` that resolves to `()` on success.
23+
pub fn UnregisterCommand<Runtime>(
24+
SidecarIdentifier:String,
25+
CommandIdentifier:String,
26+
) -> ActionEffect<Arc<Runtime>, CommonError, ()>
27+
where
28+
Runtime: AppRuntime + Send + Sync + 'static,
29+
Runtime::EnvironmentType: Requires<Arc<dyn CommandExecutor>>, {
30+
ActionEffect::New(Arc::new(move |Runtime:Arc<Runtime>| {
31+
let SidecarIdentifierClone = SidecarIdentifier.clone();
32+
let CommandIdentifierClone = CommandIdentifier.clone();
33+
Box::pin(async move {
34+
let Environment = Runtime.GetEnvironment();
35+
let Executor:Arc<dyn CommandExecutor> = Environment.Require();
36+
Executor.UnregisterCommand(SidecarIdentifierClone, CommandIdentifierClone).await
37+
})
38+
}))
39+
}

Source/command/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
/**
4+
* @module command
5+
* @description This module defines the abstract contract for the Command service.
6+
* It includes the `CommandExecutor` trait and the `ActionEffect` constructors for
7+
* all command operations.
8+
*/
9+
10+
#![allow(non_snake_case, non_camel_case_types)]
11+
12+
// --- Trait Definition ---
13+
mod CommandExecutor;
14+
pub use self::CommandExecutor::CommandExecutor;
15+
16+
// --- Effect Constructors ---
17+
mod ExecuteCommand;
18+
mod GetAllCommands;
19+
mod RegisterCommand;
20+
mod UnregisterCommand;
21+
22+
pub use self::ExecuteCommand::ExecuteCommand;
23+
pub use self::GetAllCommands::GetAllCommands;
24+
pub use self::RegisterCommand::RegisterCommand;
25+
pub use self::UnregisterCommand::UnregisterCommand;

Source/config/ConfigInspector.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use async_trait::async_trait;
2+
3+
/// @module ConfigInspector
4+
/// @description Defines the abstract service trait for inspecting the sources
5+
/// of configuration values.
6+
use super::dto::{ConfigurationOverridesDto, InspectResultDataDto};
7+
use crate::{environment::Environment, error::CommonError};
8+
9+
/// An abstract service contract for an environment component that can inspect
10+
/// a configuration key to provide details about its value in all relevant
11+
/// scopes (e.g., default, user, workspace) and its final effective value.
12+
///
13+
/// This is used to power the "Settings" UI, which often shows where a
14+
/// particular setting is defined.
15+
#[async_trait]
16+
pub trait ConfigInspector: Environment + Send + Sync {
17+
/// Inspects a configuration key to get its value from all relevant scopes.
18+
///
19+
/// @param Key - The dot-separated configuration key to inspect.
20+
/// @param Overrides - A DTO specifying scope overrides (e.g., for a
21+
/// specific resource).
22+
///
23+
/// @returns A `Result` containing an `Option<InspectResultDataDto>`, which
24+
/// holds the detailed breakdown of the key's values across all scopes.
25+
async fn InspectConfigurationValue(
26+
&self,
27+
Key:String,
28+
Overrides:ConfigurationOverridesDto,
29+
) -> Result<Option<InspectResultDataDto>, CommonError>;
30+
}

Source/config/ConfigProvider.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use async_trait::async_trait;
2+
use serde_json::Value;
3+
4+
/// @module ConfigProvider
5+
/// @description Defines the abstract service trait for providing and updating
6+
/// configuration values.
7+
use super::dto::{ConfigurationOverridesDto, ConfigurationTarget};
8+
use crate::{environment::Environment, error::CommonError};
9+
10+
/// An abstract service contract for an environment component that can provide
11+
/// the final, merged configuration values and handle requests to update those
12+
/// values in their persistent storage (i.e., `settings.json` files).
13+
#[async_trait]
14+
pub trait ConfigProvider: Environment + Send + Sync {
15+
/// Retrieves a configuration value for a given section/key, applying
16+
/// specified overrides. This should return the final, effective value
17+
/// after merging all configuration sources.
18+
///
19+
/// @param Section - An optional, dot-separated key to a specific
20+
/// configuration section. If `None`, the entire configuration object
21+
/// should be returned. @param Overrides - A DTO specifying scope overrides
22+
/// (e.g., for a specific resource).
23+
///
24+
/// @returns A `Result` containing the requested configuration as a
25+
/// `serde_json::Value`.
26+
async fn GetConfigurationValue(
27+
&self,
28+
Section:Option<String>,
29+
Overrides:ConfigurationOverridesDto,
30+
) -> Result<Value, CommonError>;
31+
32+
/// Updates a configuration value at a specific key and target scope.
33+
///
34+
/// @param Key - The dot-separated configuration key to update.
35+
/// @param ValueToSet - The new `serde_json::Value` to set for the key.
36+
/// @param Target - The `ConfigurationTarget` enum specifying which scope to
37+
/// write to (e.g., User, Workspace).
38+
/// @param Overrides - A DTO for scope overrides.
39+
/// @param ScopeToLanguage - An optional flag related to language-specific
40+
/// settings.
41+
async fn UpdateConfigurationValue(
42+
&self,
43+
Key:String,
44+
ValueToSet:Value,
45+
Target:ConfigurationTarget,
46+
Overrides:ConfigurationOverridesDto,
47+
ScopeToLanguage:Option<bool>,
48+
) -> Result<(), CommonError>;
49+
}

Source/config/GetConfiguration.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::sync::Arc;
2+
3+
use serde_json::Value;
4+
5+
/// @module GetConfiguration
6+
/// @description Defines the ActionEffect for retrieving a configuration value
7+
/// or section.
8+
use super::{ConfigProvider::ConfigProvider, dto::ConfigurationOverridesDto};
9+
use crate::{
10+
effect::{ActionEffect, AppRuntime},
11+
environment::Requires,
12+
error::CommonError,
13+
};
14+
15+
/// Creates an effect that, when executed, will retrieve the final, merged
16+
/// configuration value for a given section, applying any specified overrides.
17+
///
18+
/// It uses the `ConfigProvider` capability from the environment to perform the
19+
/// operation.
20+
///
21+
/// @param Section - An optional, dot-separated key to a specific configuration
22+
/// section. If `None`, the entire configuration object is returned.
23+
/// @param OverridesValue - A `serde_json::Value` representing the
24+
/// `ConfigurationOverridesDto`, which can specify a resource or language
25+
/// scope.
26+
///
27+
/// @returns An `ActionEffect` that resolves with a `serde_json::Value`
28+
/// containing the requested configuration.
29+
pub fn GetConfiguration<Runtime>(
30+
Section:Option<String>,
31+
OverridesValue:Value,
32+
) -> ActionEffect<Arc<Runtime>, CommonError, Value>
33+
where
34+
Runtime: AppRuntime + Send + Sync + 'static,
35+
Runtime::EnvironmentType: Requires<Arc<dyn ConfigProvider>>, {
36+
ActionEffect::New(Arc::new(move |Runtime:Arc<Runtime>| {
37+
let SectionClone = Section.clone();
38+
let OverridesValueClone = OverridesValue.clone();
39+
Box::pin(async move {
40+
let Environment = Runtime.GetEnvironment();
41+
let Provider:Arc<dyn ConfigProvider> = Environment.Require();
42+
43+
let OverridesParsed:ConfigurationOverridesDto =
44+
serde_json::from_value(OverridesValueClone).map_err(|e| {
45+
CommonError::InvalidArg {
46+
ArgumentName:"OverridesValue".to_string(),
47+
Reason:format!("Failed to parse ConfigurationOverridesDto: {}", e),
48+
}
49+
})?;
50+
51+
Provider.GetConfigurationValue(SectionClone, OverridesParsed).await
52+
})
53+
}))
54+
}

0 commit comments

Comments
 (0)