面向 MoonBit 解释器、虚拟机和 DSL 的 DAP 服务端开发包
| 路径 | 作用 |
|---|---|
| framing/、protocol/ | 增量字节分帧,以及从固定 DAP Schema 生成的类型和编解码。 |
| session/、transport/ | 会话状态、能力协商和目标接口,以及 native stdio、回环 TCP。 |
| expression/ | 有界的 JSON 表达式解析、求值及赋值路径。 |
| examples/ | 迷你解释器、第三方 MoonBpfLab 适配器及多源码规则引擎。 |
| tests/、scripts/ | 测试夹具、真实会话回归、Schema 生成、打包验证和源码统计。 |
| vendor/dap/、docs/ | 固定的上游规范及许可证,以及设计、覆盖范围和验收记录。 |
moon update
moon add wccerty/moon-dap@0.2.1
moon add moonbitlang/async@0.20.6members = ["interpreter", "moon-dap"]import {
"moonbitlang/async@0.20.6",
"wccerty/moon-dap@0.2.1",
}import {
"moonbitlang/async",
"wccerty/moon-dap/session",
"wccerty/moon-dap/transport",
}
supported_targets = "+native"
pkgtype(kind: "executable")struct OneLine {
mut sink : @session.EventSink?
mut ready : Bool
}
impl @session.DebugTarget for OneLine with fn prepare(self, mode, _, sink) {
guard mode is Launch else { raise @session.TargetError("需要 launch") }
self.sink = Some(sink)
}
impl @session.DebugTarget for OneLine with fn start(self) {
guard self.sink is Some(sink) else { raise @session.TargetError("缺少会话") }
sink.emit(Stopped({ reason: Entry, thread_id: 1, description: None, breakpoint_ids: [] }))
}
impl @session.DebugTarget for OneLine with fn set_breakpoints(_, _, _) { raise @session.TargetError("没有可配置的源码") }
impl @session.DebugTarget for OneLine with fn resume_execution(self, _, _) { self.ready = true }
impl @session.DebugTarget for OneLine with fn pause(_, _) { () }
impl @session.DebugTarget for OneLine with fn threads(_) { [{ id: 1, name: "主线程" }] }
impl @session.DebugTarget for OneLine with fn stack_trace(_, _, _) { { frames: [], total: 0L } }
impl @session.DebugTarget for OneLine with fn scopes(_, _) { [] }
impl @session.DebugTarget for OneLine with fn variables(_, _, _) { [] }
impl @session.DebugTarget for OneLine with fn disconnect(self, _) { self.sink = None }
impl @session.DebugTarget for OneLine with fn poll(self) {
if self.ready && self.sink is Some(sink) {
self.ready = false
sink.emit(Output("stdout", "hello\n"))
sink.emit(Exited(0))
}
}
async fn main { @transport.serve_stdio(OneLine::{ sink: None, ready: false }) }| 接口 | 负责的工作 |
|---|---|
| session.DebugTarget.prepare / start / disconnect | 启动或附加、等待配置完成、终止或分离。 |
| set_breakpoints | 按路径替换一组行断点,空数组清除,逐项返回实际位置和验证状态。坐标统一为 1 基。 |
| breakpoint_location_provider | 可选。为编辑器查询给定源码范围内可设断点的位置。范围包含端点,列号以 UTF-16 代码单元计。 |
| conditional_breakpoint_provider | 可选。用目标自己的语法处理条件断点,并返回验证结果。 |
| evaluation_provider | 可选。读取暂停状态中的表达式值,支持编辑器监视和悬停。 |
| source_provider | 可选。提供会话级内存源码引用,支持列举、读取和下断点。 |
| breakpoint_providers | 可选。提供函数断点,并按目标声明启用命中次数和日志断点。 |
| inspection_providers | 可选。提供展开式求值、修改变量、表达式赋值、补全和异常快照。 |
| resume_execution / pause / poll | 接受执行命令并推进有界工作,在安全点发送停止事件。 |
| threads / stack_trace / scopes / variables | 通过目标句柄提供栈和变量。一次暂停中的句柄须稳定,恢复后由库废弃对外引用。 |
| session.EventSink.emit | 发送停止、输出、退出和终止等通知。 |
| transport.serve_stdio / listen_loopback / serve_tcp | 在 native 上驱动会话。TCP 的目标工厂为每个连接创建独立实例。 |
| transport.serve | 在已有异步 reader 和 writer 上接入一个会话。 |
| framing / protocol | 独立的 UTF-8 字节分帧、DAP 类型与 JSON 编解码。 |
| expression | 在 JSON 值上执行受限的调试表达式,支持字段、下标和复制后写回。 |
| 示例 | 演示场景 | 验证方式 |
|---|---|---|
| 迷你解释器 | 源码断点、函数步进、嵌套变量。 | stdio、TCP 端到端测试及 VS Code 实测。 |
| MoonBpfLab | 条件断点、寄存器求值、ELF 源码映射、跨文件断点和调用栈。 | 使用真实第三方 VM,已通过 VS Code 和 Neovim 实测。 |
| 规则引擎 | 内存源码、函数和日志断点、可写变量、异常栈。 | stdio 测试验证调试时的赋值会改变执行结果。 |
| Schema 项目 | 当前版本覆盖 | 总数 |
|---|---|---|
| 请求 | 25,含按目标能力启用的动态源码、函数断点、赋值及补全 | 45 |
| 事件 | 7 | 17 |
| Capabilities | 13 | 42 |
| 手写代码 | 物理行 | 有效行估算 |
|---|---|---|
| 核心库 | 2,851 | 2,440 |
| 可运行示例 | 2,560 | 2,251 |
| 测试与夹具 | 1,752 | 1,567 |
| 合计 | 7,163 | 6,258 |
moon update
python -m pip install -r tests/requirements.txt
npm ci --prefix tests --ignore-scripts --no-audit --no-fund
moon check --target native --deny-warn
moon fmt --check
moon info --target native
git diff --exit-code -- ':(glob)**/pkg.generated.mbti'
python scripts/generate_protocol.py --check
moon test --target native --deny-warn
moon build --target native
python scripts/check_schema.py
python scripts/test_e2e.py
python scripts/test_rules.py
node --test tests/vscode_client.cjs
python scripts/test_bpflab.py