Skip to content

Debug Adapter (DAP)

lash provides script debugging via two mechanisms: CLI debug flags for simple logging, and a full Debug Adapter Protocol (DAP) implementation for IDE integration.

Logs script comments and command executions to stderr:

lash script.lash --log-verbose
EventFormat
Comment[debug] # comment text
Pipeline[exec] program args | program args

Pipeline commands are logged after variable expansion.

Logs variable mutations to stderr. Accepts an optional comma-separated name filter:

lash script.lash --log-variables # all variable changes
lash script.lash --log-variables x,y # only x and y
EventFormat
Declaration[var] let name = value
Assignment[var] name = value
Drop[var] drop name

Flags may be combined. All debug output goes to stderr.

lash script.lash --log-verbose --log-variables x,count

A standalone lash-debug binary speaks the Debug Adapter Protocol over stdin/stdout, enabling VS Code (or any DAP client) to set breakpoints, step through code, and inspect variables.

Architecture: Lives in backend/debug/. Depends on backend/, lang/, runtime/. Does not import frontend/ or plugins/.

An onBeforeStatement callback in ExecCallbacks. When set, called before each statement. Returns FlowSignal.none to continue or FlowSignal.break_ to pause.

MVP uses single-threaded with nested event loop: when a breakpoint hits, onBeforeStatement enters a nested DAP request loop until continue/step.

RequestDescription
initializeCapabilities exchange.
launchStart script. Params: program, args, stopOnEntry, cwd.
disconnectClean shutdown.
configurationDoneStart execution.
setBreakpointsSet breakpoints for a source file.
setExceptionBreakpointsAccept but ignore (no exception hierarchy).
threadsSingle thread.
stackTraceCurrent call stack when paused.
scopesScope chain for a stack frame.
variablesVariables in a scope.
continueResume execution.
nextStep over.
stepInStep into.
stepOutStep out.
EventWhen
initializedAfter initialize response.
stoppedBreakpoint hit, step completed.
terminatedScript finished.
outputScript produced stdout/stderr.
threadThread started (once, threadId: 1).

When paused, the debugger exposes the scope chain for each stack frame. Structured values (lists, objects) get their own variable references for drill-down inspection.

A minimal extension at editors/vscode/ registers the “lash” debug type using DebugAdapterExecutable to spawn lash-debug directly.