Common/Command/
RegisterCommand.rs

1//! # RegisterCommand Effect
2//!
3//! Defines the `ActionEffect` for registering a command that is implemented in
4//! an external sidecar process.
5
6use std::sync::Arc;
7
8use super::CommandExecutor::CommandExecutor;
9use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
10
11/// Creates an effect that, when executed, will register a command that is
12/// implemented in a sidecar process like Cocoon.
13///
14/// This allows the host application (`Mountain`) to know about commands
15/// contributed by extensions so they can be displayed in the command palette
16/// and invoked correctly. The `CommandExecutor` implementation will typically
17/// store this as a `Proxied` command handler.
18///
19/// # Parameters
20///
21/// * `SideCarIdentifier`: The unique ID of the sidecar where the command logic
22///   resides.
23/// * `CommandIdentifier`: The unique ID of the command itself (e.g.,
24
25///   "MyExtension.DoSomething").
26///
27/// # Returns
28///
29/// An `ActionEffect` that resolves to `()` on success.
30pub fn RegisterCommand(
31	SideCarIdentifier:String,
32
33	CommandIdentifier:String,
34) -> ActionEffect<Arc<dyn CommandExecutor>, CommonError, ()> {
35	ActionEffect::New(Arc::new(move |Executor:Arc<dyn CommandExecutor>| {
36		let SideCarIdentifierClone = SideCarIdentifier.clone();
37
38		let CommandIdentifierClone = CommandIdentifier.clone();
39
40		Box::pin(async move { Executor.RegisterCommand(SideCarIdentifierClone, CommandIdentifierClone).await })
41	}))
42}