面向 MoonBit 解释器、虚拟机和 DSL 的 DAP 服务端开发包
moon update
moon add wccerty/moon-dap@0.2.0
moon add moonbitlang/async@0.20.6members = ["interpreter", "moon-dap"]import {
"moonbitlang/async@0.20.6",
"wccerty/moon-dap@0.2.0",
}import {
"moonbitlang/async",
"wccerty/moon-dap/session",
"wccerty/moon-dap/transport",
}
supported_targets = "+native"
options("is-main": true)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 值上执行受限的调试表达式,支持字段、下标和复制后写回。 |
| Schema 项目 | 当前版本覆盖 | 总数 |
|---|---|---|
| 请求 | 25,含按目标能力启用的动态源码、函数断点、赋值及补全 | 45 |
| 事件 | 7 | 17 |
| Capabilities | 13 | 42 |
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
python scripts/generate_protocol.py --check
moon test --target native
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