Nimala::Raku-LSP — Nimala::Raku-DAP
NAME
Nimala::Raku-DAP - The Raku Debug Adapter Protocol (DAP) Server
DESCRIPTION
This module implements the Debug Adapter Protocol (DAP) for Raku. It serves as the main broker between the IDE (such as VS Code, Neovim, or Emacs) and the target Raku process being debugged.
Supported DAP Features
Launch: Launching scripts with custom CLI arguments and environment variables.
Line Breakpoints: Setting line breakpoints with smart alignment to executable statements and conditional expressions.
Logpoints: Setting non-breaking logpoints with dynamic expression interpolation.
Function Breakpoints: Breakpoints by routine name with conditional evaluation.
Exception Breakpoints: Automatic pause on uncaught and all exceptions with full stack trace and exceptionInfo inspection.
Execution Stepping: Step Over (`next`), Step In (`stepIn`), Step Out (`stepOut`), Pause (`pause`), and Continue (`continue`).
Threads & Call Stacks: Multi-threaded stack frame inspection with file locations, line numbers, and active subroutine names.
Variable Inspection: Inspection of Lexical (`Locals`) scopes with lazy navigation of object attributes, positionals, and associatives.
Interactive REPL & Evaluation: Real-time bounded expression evaluation in the debug console with safe `.gist` inspection.
Architecture: Native MoarVM Remote Debugging Protocol
This DAP server communicates directly with MoarVM's built-in remote debugging protocol over loopback TCP using MessagePack framing.
Native VM-Level Execution: The debuggee runs as standard
raku --debug-port=<port> --debug-suspend <program>, executing standard precompiled bytecode. This eliminates the precompilation slot mismatches, slow first launches, and compilerwhenstatement crashes of earlier statement-hook implementations.Pure-Raku MessagePack Framing: Communication uses a fast, dependency-free MessagePack codec and protocol client with monotonic request/response correlation and event dispatch.
Monotonic Handle Management: Context and object handles allocated during stops are tracked in a lifecycle registry and cleanly released in batches upon resume or disconnect.
Bounded Expressions & Safe Inspection: Expression evaluation, conditional breakpoints, and logpoints use a bounded expression grammar (variables, attribute/key/index access, comparisons against literals). Arbitrary method calls and mutations are refused; only the whitelisted helpers
.gist,.Str,.rakuand.elemsrun in the debuggee, at most one per stop.Smart Stepping: Configurable smart stepping (
into,over,disable) automatically filters out internal compiler, runtime, and NQP frames on builds without line drift, while robust sweep stepping protects stepping on builds with bytecode line drift.
Public Interface
The public interface of this module is minimal as it primarily acts as an entry point for the DAP server binary.
run-dap-server(): Starts the DAP event loop, reading DAP messages from standard input, translating them to MoarVM protocol commands, and relaying events back to the client.