Expand description
§DebugProvider (Environment)
RESPONSIBILITIES:
- Implements
DebugServiceforMountainEnvironment - Manages complete debugging session lifecycle from configuration to termination
- Orchestrates between extension host (Cocoon), debug adapter, and UI
- Handles DAP (Debug Adapter Protocol) message mediation
ARCHITECTURAL ROLE:
- Core provider for debugging functionality, analogous to VSCode’s debug service
- Uses two-stage registration: configuration providers and adapter descriptor factories
- Each debug type (node, java, rust) can have its own configuration and adapter
- Integrates with
IPCProviderfor RPC to Cocoon
DEBUG SESSION FLOW:
- UI calls
StartDebuggingwith folder URI and configuration - Mountain RPCs to Cocoon to resolve debug configuration (variable substitution)
- Mountain RPCs to Cocoon to create debug adapter descriptor
- Mountain spawns debug adapter process or connects to TCP server
- Mountain mediates DAP messages between UI and debug adapter
- UI sends DAP commands via
SendCommandwhich forwards to adapter - Debug adapter sends DAP events/notifications back through Mountain to UI
- Session ends on stop request or adapter process exit
ERROR HANDLING:
- Uses
CommonErrorfor all operations - Validates debug type is non-empty (InvalidArgument error)
- TODO: Implement proper session lookup, timeout handling, and error recovery
PERFORMANCE:
- Debug adapter spawning should be async with timeout protection (5000ms in current RPC)
- DAP message routing needs efficient session lookup (TODO: O(1) hash map)
- Multiple simultaneous debug sessions require careful resource management
VS CODE REFERENCE:
vs/workbench/contrib/debug/browser/debugService.ts- debug service main logicvs/workbench/contrib/debug/common/debug.ts- debug interfaces and modelsvs/workbench/contrib/debug/browser/adapter/descriptorFactory.ts- adapter descriptor factoriesvs/debugAdapter/common/debugProtocol.ts- DAP protocol specification
IMPLEMENTED:
- Provider/factory registrations stored in ApplicationState (DebugState)
- Active session tracking via DebugState::DebugSessions map
- Executable adapter spawning with stdin/stdout/stderr pipes
- DAP frame parsing (Content-Length header + JSON body) on adapter stdout
- Stdout messages emitted on
sky://debug/dap-messagefor renderer pickup - SendCommand serialises DAP request → writes framed bytes to stdin
- StopDebugging sends DAP
disconnectrequest then unregisters session
FOLLOWUP:
server/pipeServeradapter connection (TCP / named-pipe)- Reverse-RPC
$sendDAPRequestCocoon handler for inline-impl adapters - Per-session request_seq allocation (currently caller-supplied)
- Adapter crash detection: when stdout EOFs unexpectedly, emit
$onDidTerminateDebugSessionso the workbench tears down its session view (today the user sees a stale session row) - Debug console / variable inspection integration
- Telemetry for adapter spawn duration, session length, exit codes
MODULE CONTENTS:
DebugServiceimplementation:RegisterDebugConfigurationProvider- register config resolverRegisterDebugAdapterDescriptorFactory- register adapter factoryStartDebugging- start debug session (partial)SendCommand- send DAP command to adapter (stub)