Skip to main content

Module CommandProvider

Module CommandProvider 

Source
Expand description

CommandExecutor provider: runs shell commands in a managed subprocess.

§CommandProvider

Implements CommandExecutor for MountainEnvironment - the central registry and dispatcher for all commands in Mountain. Commands are identified by string IDs and handled either by native Rust functions or proxied to extension sidecar processes via IPC.

§Execution flow

  1. Caller invokes ExecuteCommand(id, args).
  2. Provider looks up id in ApplicationState::CommandRegistry.
  3. Native handler: calls the Rust function pointer directly with AppHandle, the main WebviewWindow, ApplicationRunTime, and args.
  4. Proxied handler: sends an RPC request to the owning extension sidecar via the Vine IPC client.
  5. Returns a serialized serde_json::Value result or a CommonError.

§Special-case no-ops

Three categories of unknown commands are silently returned as Value::Null rather than an error, to match VS Code’s behaviour:

  • View-action auto-commands (.focus, .resetViewLocation, .removeView)
  • Workbench-internal commands with no Land backing service (getTelemetrySenderObject, testing.clearTestResults)
  • Bootstrap-phase activation-race commands (_typescript.*, etc.)

§Lazy activation

If a command is not yet in the registry but a scanned extension declares onCommand:<id> as an activation event, ExecuteCommand fires $activateByEvent to Cocoon, yields 50 ms for the fire-and-forget registerCommand notification to arrive, then retries the lookup.

§Backlog

  • Contribution points from extensions; enablement/disable state
  • Categories, grouping, aliases, deprecation
  • History and undo/redo stack; keyboard shortcut resolution
  • Permission validation; batching for related operations; telemetry

VS Code reference: vs/platform/commands/common/commands.ts, vs/workbench/services/commands/common/commandService.ts.

Enums§

CommandHandler
An enum representing the different ways a command can be handled.

Functions§

LookupCommandContributingExtension 🔒
Return true when some scanned extension declares onCommand:<CommandIdentifier> as one of its activation events. Used by the lazy-activation fallback in ExecuteCommand - without this check we’d fire an $activateByEvent("onCommand:X") for every unknown command, which would cause Cocoon to log “no extension matching event” for every typo. Scans the cached registry; no IPC.