Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/
Commands.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Command registry handlers - execute and list all registered commands.
4
5use std::sync::Arc;
6
7use CommonLibrary::Command::CommandExecutor::CommandExecutor;
8use serde_json::{Value, json};
9use tauri::Emitter;
10
11use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
12
13/// Execute a command by ID, dispatching to Mountain's CommandExecutor.
14/// Emits `sky://commands/executed` after dispatch so subscribers of
15/// `vscode.commands.onDidExecuteCommand` (telemetry collectors, vim,
16/// gitlens) observe every command that runs through Mountain.
17pub async fn CommandsExecute(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
18	let CommandId = Arguments
19		.first()
20		.and_then(|V| V.as_str())
21		.ok_or_else(|| "commands:execute requires string command_id as first argument".to_string())?
22		.to_string();
23
24	let CommandArgs:Vec<Value> = Arguments.into_iter().skip(1).collect();
25
26	let Argument = CommandArgs.first().cloned().unwrap_or(Value::Null);
27
28	dev_log!("ipc", "commands:execute id={}", CommandId);
29
30	let Result = RunTime
31		.Environment
32		.ExecuteCommand(CommandId.clone(), Argument)
33		.await
34		.map_err(|Error| format!("commands:execute failed: {}", Error));
35
36	// Broadcast to `vscode.commands.onDidExecuteCommand` subscribers.
37	// Fire-and-forget; failure is non-fatal.
38	let _ = RunTime.Environment.ApplicationHandle.emit(
39		"sky://commands/executed",
40		json!({ "command": CommandId, "arguments": CommandArgs }),
41	);
42
43	Result
44}
45
46/// Return all registered command IDs from Mountain's CommandRegistry.
47pub async fn CommandsGetAll(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
48	let Commands = RunTime
49		.Environment
50		.GetAllCommands()
51		.await
52		.map_err(|Error| format!("commands:getAll failed: {}", Error))?;
53
54	Ok(json!(Commands))
55}