Repository navigation
feat(debug): targetBindings 可绑定适配器自有参数,cwd 可取源文件所在目录 - #55
Merged
Merged
Conversation
调试配置的 targetBindings 新增 adapterArguments:键是适配器自己定义的顶层 DAP 参数名,值只能是 target.path、target.directory、target.workingDirectory 三个路径事实之一。宿主照常只补缺省的参数。用途是让 Delve 的 dlvCwd 指向 当前文件所在的包目录:工作区根没有 go.mod 时,Delve 在自己的 cwd 编译会报 "go.mod file not found",被调程序的 cwd 也不对。 校验规则: - 1-8 项,参数名必须是顶层名字(不含点)。 - 不能是 program、processId、cwd、args、env,它们有各自的绑定。 - 不能是 noDebug 或 __ 开头的宿主参数。 - 不能和配置自己的 arguments 重名,也不能和 connection 的目标路径重叠。 - 计划阶段目标缺少对应事实时,报 debug.target.invalid,字段为 target.path 或 target.workingDirectory。 契约 README、schema、拒绝 fixture、rust-core-api.md、调试适配器指南与领域页、 协议更新记录同步更新;属于 debugAdapters 0 内的补充,不升能力版本。
Delve 切到 dlvCwd 后不改 PWD,go build 在路径经过符号链接(例如 macOS 的 /var → /private/var)时会用错目录,报 outside main module。Go 插件需要同时 绑定 env.PWD ← target.directory。 - adapterArguments 的键改为和 connection 目标一样的点分路径(最多 4 段) - env.<变量名> 只加一个变量,保留 arguments 和 env 绑定给的变量,目标环境 自己设的同名变量优先 - 其他固定绑定、宿主保留名、路径重叠、落在默认值上或下面的路径都拒绝 - 新增拒绝样例和填充测试,更新 schema、契约 README、指南、领域参考、 Core API 文档和协议更新记录
xiaoyumuxi
marked this pull request as ready for review
November 15, 2026 10:14
19 of 22 tasks
This was referenced Nov 15, 2026
xiaoyumuxi
added a commit
that referenced
this pull request
Nov 15, 2026
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Go 插件的 Delve 调试配置把
program绑到target.directory(当前文件所在目录),但宿主启动dlv dap时用的工作目录是工作区根,PWD也设成工作区根。工作区根没有go.mod、模块在子目录时启动就失败,例如打开的是课程目录,模块在cnscc368-4/,报错是Failed to launch: Build error ... go.mod file not found。被调程序的 cwd 也跟着变成工作区根,examples/topo1.txt这类相对路径打不开。一个工作区里并排放好几个独立模块,是很常见的布局。用 Delve 1.27.2 的 DAP 实测(探针直接起
dlv dap,cwd 和PWD与宿主一致),结论如下:os.Chdir(dlvCwd),再设置 DAPenv里的变量,最后运行go build,而且不更新PWD。cwd为空时,被调程序也在dlvCwd运行,__debug_bin*也生成在dlvCwd。dlvCwd不够。go只在PWD和真实目录一致时才用PWD。路径经过符号链接时(macOS 的/var→/private/var),go改用真实路径:directory ... outside main module;could not find file。env.PWD← 包目录后,以下布局都能编译、命中断点、读到相对路径的文件,调试结束后没有残留二进制:go.mod、模块在子目录;cmd/tool);go.mod的单文件或多文件目录,用program: "."加GO111MODULE=auto(GOPATH 模式)也能调试。这两个是常量,写在 Go 插件自己的arguments里,不需要 Core 支持。现有
targetBindings只有program、processId、cwd、args、env和connection这几个固定字段,插件没办法把目标的路径事实交给适配器自己定义的参数,也没办法往环境里加一个变量。这个 PR 在
targetBindings里加一个映射adapterArguments:connection的目标一样用点分隔;env.<变量名>往环境里加一个变量。Go 插件以后写
"adapterArguments": {"dlvCwd": "target.directory", "env.PWD": "target.directory"}。端到端测试还暴露了第二个问题:调试引擎
perform_launch(rust/crates/debug/src/engine.rs)在 launch 参数缺cwd时,会把cwd填成工作区根目录,所以被调程序仍在根目录运行,按包目录读的相对路径文件找不到。因此targetBindings.cwd除了target.workingDirectory,现在也可以绑到target.directory,被调程序就在源文件所在目录运行。这两处都归入 API-30(调试适配器),属于
debugAdapters0 内的补充,不升能力版本。改动
清单与校验(
rust/crates/debug/src/adapters/declaration.rs、validate_configuration.rs、adapters.rs)DebugTargetBindings新增adapterArguments?: { [path]: fact },fact只能是target.path、target.directory、target.workingDirectory。launch和attach都可以用。只写了adapterArguments的绑定也不算空绑定。plugin.manifest.invalid。…targetBindings.adapterArguments的两条:is_argument_path检查:最多 4 段,每段是合法参数名,和connection目标的规则相同。…adapterArguments.<路径>:env时,后面只能再跟一段,也就是一个变量名。env本身和env.a.b都拒绝。program、processId、cwd、args时拒绝,它们各有绑定,也不能伸进去。noDebug或以__开头时拒绝,这些是宿主参数。判断改用backend_start::is_host_key,和后端配置的检查共用一处。dlv和dlv.cwd。arguments已有的值上或它的下面时拒绝,途经的值不是对象也拒绝。判断用default_occupies。connection的目标路径不能和adapterArguments的路径重叠,按原来的connection字段报错。targetBindings.cwd的允许值从只有target.workingDirectory扩到target.workingDirectory或target.directory,其他值报cwd can only be bound to target.workingDirectory or target.directory.。计划与启动参数(
plan.rs、start.rs)plan():目标缺少cwd或某个adapterArguments需要的事实时,返回debug.target.invalid(cwd与adapterArguments共用一段检查):target.workingDirectory;target.path。bound_arguments()在env绑定之后按事实取值,只补没有值的路径。env.PWD会加进arguments的env或env绑定给的环境里,原有变量都保留。env时新建一个。path_fact():三个事实的取值收在这一处;fill_argument():按路径补值,已有值时保留;argument_parent():沿路径找到父对象,途经的对象自动创建;occupied_argument():途经的值不是对象时的debug.arguments.invalid拒绝。connection原来用的set_argument()改为共用argument_parent(),行为不变。cwd绑定也改用path_fact()取值,target.directory取源文件所在目录。契约与文档
plugin-manifest.schema.json:targetBindings.cwd从const改为target.workingDirectory、target.directory的枚举。新增targetBindings.adapterArguments。minProperties为 1,maxProperties为 8;propertyNames复用debugArgumentPath;值是三个事实的枚举。contract/v1/README.md:调试适配器字段表新增targetBindings.adapterArguments一行,写明路径规则、env.<变量名>、错误码,并给出 Delve 示例和原因。fixtures/debug-adapters/debug-adapter-rejections.json:新增 17 个拒绝用例,覆盖上面每条校验规则和两个计划阶段的错误,其中cwd-from-target-path拒绝把cwd绑到target.path。例如env、env.PWD.dir、program.dir、a.b.c.d.e、互相重叠的路径,以及落在非对象默认值下面的路径。rust/contracts/rust-core-api.md:补充adapterArguments的取值方式、填入顺序和debug.target.invalid的字段。guides/debug-adapter-plugin.md;reference/domains/debug-adapters.md。rust-core-api.md同时写明cwd←target.directory,以及调试引擎在缺cwd时用工作区根目录。reference/protocol-changelog.md:2026-11-15 新增一行,API-30,属于debugAdapters0 内的补充,包含adapterArguments和cwd←target.directory。测试(
rust/crates/core/src/tests/declarative_plugins.rs)debug_start_arguments_fill_adapter_arguments_from_path_facts:三个事实都能填进启动参数;缺工作目录时报target.workingDirectory。debug_start_arguments_add_an_adapter_argument_to_the_environment覆盖三种情况:env.PWD加进arguments.env,GO111MODULE保留;env绑定的目标环境时,目标自己的PWD不被覆盖;debug_adapter_arguments_survive_manifest_normalization:清单规范化后adapterArguments原样保留。debug_start_arguments_bind_cwd_to_the_directory_of_the_target:cwd←target.directory取源文件所在目录,cwd←target.workingDirectory不变;裸文件名路径报target.path,缺工作目录报target.workingDirectory。debug_start_arguments_fill_adapter_arguments_from_path_facts同时绑cwd←target.directory,检查启动参数里的cwd。debug_adapter_rejection_fixtures_report_their_code_and_field逐条执行。验证
下面这组在 671cdc6 上跑过。268d9a2(
cwd←target.directory)上重跑了cargo fmt --all -- --check、cargo clippy --locked -p lithe-debug -p lithe-core --all-targets --all-features -- -D warnings、同两个 crate 的 Windows 目标 clippy、cargo test --locked -p lithe-debug -p lithe-core -p lithe-plugin-model(lithe-core 810 个测试)、注释校验、verify-platform-tests.mjs和verify-docs.mjs,全部通过。cargo fmt --all -- --checknode scripts/logging/generate-log-events.mjs --checkscripts/rust-core/verify-rust-core-comments.sh debug corecargo clippy --locked --workspace --all-targets --all-features -- -D warningscargo clippy --locked -p lithe-debug -p lithe-core --target x86_64-pc-windows-msvc --all-targets -- -D warningscargo test --locked --workspace:809 个 lithe-core 测试和其余 crate 全部通过。lsp_process::terminating_a_language_server_ends_the_processes_it_started在本机全量并行时超时过一次,单独重跑通过,和本改动无关。node scripts/rust-core/verify-platform-tests.mjsnode shared/plugins/scripts/verify-docs.mjs后续
arguments:{"mode":"debug","program":".","env":{"GO111MODULE":"auto"}};targetBindings:{"cwd":"target.directory","args":"target.arguments","adapterArguments":{"dlvCwd":"target.directory","env.PWD":"target.directory"}},去掉program和env绑定。fix/delve-dlvcwd-package-directory分支。PINNED_CORE_REVISION升到合入后的 commit。旧宿主不认识adapterArguments(deny_unknown_fields),所以 Go 插件要等带本 PR 的桌面端版本发布后再发版。