Expand description
§CommandProvider (Environment)
Implements the CommandExecutor trait, serving as the central registry and
dispatcher for all commands in the Mountain application. Commands can be
handled either by native Rust handlers or proxied to extension sidecar
processes.
§RESPONSIBILITIES
§1. Command Registry
- Maintain centralized registry of all registered commands
- Store command metadata (id, title, category, flags)
- Track command source (native vs extension)
- Support command enablement/disable state
§2. Command Dispatching
- Route command execution requests to appropriate handlers
- Execute native commands directly via function calls
- Proxy extension commands via IPC to sidecar processes
- Handle command result propagation and error translation
§3. Command Execution Context
- Provide
CommandExecutorcapability to command handlers - Manage command scope (text editor, file system, etc.)
- Track command invocation source and user context
- Support command cancellation for long-running operations
§4. Command Discovery
- Enumerate all registered commands for UI display
- Support command palette and quick open
- Provide command categories and visibility rules
- Handle command contribution points from extensions
§ARCHITECTURAL ROLE
CommandProvider is the command execution hub for Mountain:
Command Caller ──► CommandProvider ──► Handler (Native or Extension)
│ │
└─► ExecuteCommand() ───────► Execute§Position in Mountain
Environmentmodule: Core capability provider- Implements
CommonLibrary::Command::CommandExecutortrait - Accessible via
Environment.Require<dyn CommandExecutor>()
§Command Sources
- Native Commands: Defined in Rust, registered at startup
- Extension Commands: Defined in package.json, contributed by extensions
- Built-in Commands: Core Mountain functionality
- User-defined Commands: Custom macros and keybindings (future)
§Dependencies
ApplicationState: Command registry storageIPCProvider: For proxying to extension sidecarsLog: For command execution tracing
§Dependents
- All command handlers: Use
CommandExecutorto execute other commands DispatchLogic::DispatchFrontendCommand: Main entry point- Tauri command handlers: Many invoke
ExecuteCommand - Keybinding system: Trigger commands via keyboard shortcuts
§COMMAND EXECUTION FLOW
- Request: Caller invokes
ExecuteCommand(command_id, args) - Lookup: Provider looks up command in
ApplicationState::CommandRegistry - Handler: Retrieves the associated handler (native function or extension RPC)
- Execute: Calls handler with arguments
- Result: Returns serialized JSON result or error
§NATIVE vs EXTENSION COMMANDS
§Native Commands
- Implemented directly in Rust
- Registered via
RegisterCommandfunction - Handler is a function pointer or
Arc<Fn> - Zero IPC overhead, direct call
§Extension Commands
- Defined in extension’s
package.jsoncontributes.commands - Registered when extension is activated
- Handler is RPC method to extension sidecar
- Goes through IPC layer with serialization
§ERROR HANDLING
- Command not found: Returns
CommonError::InvalidArgument - Handler errors: Propagated as
CommonError - IPC failures: Converted to
CommonError::IPCError - Serialization failures:
CommonError::SerializationError
§PERFORMANCE
- Native commands: Near-zero overhead (direct function call)
- Extension commands: IPC serialization + network latency
- Command lookup: HashMap lookup by string ID (fast)
- Consider caching frequently used command results
§VS CODE REFERENCE
Borrowed from VS Code’s command system:
vs/platform/commands/common/commands.ts- Command definitionsvs/workbench/services/commands/common/commandService.ts- Command registryvs/platform/commands/common/commandExecutor.ts- Command execution
§TODO
- Implement command contribution points from extensions
- Add command enablement/disable state management
- Support command categories and grouping
- Add command history and undo/redo stack
- Implement command keyboard shortcut resolution
- Add command telemetry (usage metrics)
- Support command aliases and deprecation
- Add command permission validation
- Implement command batching for related operations
§MODULE CONTENTS
CommandProvider: Main struct implementingCommandExecutor- Command registration functions (to be added)
- Extension command proxy logic
Enums§
- Command
Handler - An enum representing the different ways a command can be handled.