Repository navigation
fix(debug): Delve 在当前文件所在的包目录构建、调试和运行 - #10
Merged
Merged
Conversation
打开的文件夹根目录没有 go.mod、并排放多个模块时,Delve 在工作区根目录执行 go build, 报 Build error;被调程序也在根目录运行,按包目录读的相对路径文件找不到。 - targetBindings.adapterArguments:dlvCwd 和 env.PWD 绑到 target.directory,go build 在包目录执行 - targetBindings.cwd 绑到 target.directory:程序在包目录运行 - arguments 改为 program "."、env GO111MODULE=auto:没有 go.mod 的目录也能调试 - e2e 覆盖多模块工作区、子命令包和没有 go.mod 的目录 - README 与功能矩阵说明新行为和宿主依赖(Lithe-core-rust#55)
xiaoyumuxi
marked this pull request as ready for review
November 15, 2026 10:34
xiaoyumuxi
added a commit
that referenced
this pull request
Nov 15, 2026
1.0.0 预发布已撤回(release 和 tag 已删除),从包含 #10 的 main 重发: - 发布说明的调试功能补充包目录、多模块工作区、子包和没有 go.mod 的目录 - 兼容性和升级说明改为需要固定 Lithe-core-rust#55 的桌面端(1lck/Lithe-IDEA#1975) - release.yml 的预发布说明同步
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.mod,而是并排放着几个模块,例如课程目录下的cnscc368-1…4,调试其中某个模块的main.go会报Failed to launch: Build error ... go.mod file not found。原因是 Delve 在工作区根目录执行go build。即使能编译,被调程序也在根目录运行,examples/topo1.txt这类按包目录写的相对路径打不开。用 Delve 1.27.2 的 DAP 实测,需要同时满足下面三点:
dlvCwd← 包目录:Delve 先os.Chdir(dlvCwd)再执行go build。env.PWD← 包目录:Delve 不更新PWD;go只在PWD和真实目录一致时用它。路径经过符号链接(macOS 的/var)时,如果不设PWD,会报outside main module,断点报could not find file。cwd← 包目录:调试引擎在 launch 参数缺cwd时会填工作区根目录。改动
io.github.lithe-idea.go-support/plugin.json,Delve 的 launch 配置:arguments:{"mode": "debug", "program": ".", "env": {"GO111MODULE": "auto"}}。program: "."配合dlvCwd构建当前包;GO111MODULE=auto让没有go.mod的目录按 GOPATH 模式构建目录里的全部文件。targetBindings:{"cwd": "target.directory", "args": "target.arguments", "adapterArguments": {"dlvCwd": "target.directory", "env.PWD": "target.directory"}},去掉了原来的program和env绑定。e2e/host/desktop/internal/workbench/official_go_plugin_debug_e2e_test.go:新增TestOfficialGoPluginDebugsEachProjectOfAWorkspaceWithDelve。工作区根目录没有go.mod,包含:lab-1、lab-2两个模块,其中lab-2读取包目录下的examples/greeting.txt,读不到就 panic;lab-2/cmd/tool子包;go.mod的scratch目录。测试依次调试
lab-2/main.go、lab-2/cmd/tool/main.go、scratch/main.go,检查断点命中的文件和行号、程序正常结束,并确认没有留下__debug_bin*。e2e/host/lithe-host.json:测试正则加入新测试。README.md:调试一节说明包目录、多模块工作区和没有go.mod的目录。docs/feature-matrix.md:go-debug-delve更新能力说明和宿主依赖。依赖与发版
targetBindings.adapterArguments和cwd←target.directory。还依赖桌面端固定这个 Core 的 feat(desktop): Core 固定到 Lithe-core-rust#55,调试配置可绑定适配器自有参数和包目录工作目录 1lck/Lithe-IDEA#1975。adapterArguments(deny_unknown_fields),会拒绝安装这个版本。合入后不要马上发版,要等包含 #55 的桌面端版本发布。验证
node scripts/package.mjs:打包通过。TestOfficialGoPluginBuildsAndServesAModule:在固定 Core 671cdc6 的宿主分支上通过。cwd落到工作区根目录的问题(lab-2 读文件 panic),于是 Core #55 增加了cwd←target.directory。node scripts/e2e-host.mjs --ref fix/core-pin-56-merge,宿主为 fix(desktop): Core 固定版本改到 Lithe-core-rust#56 的合入提交 1lck/Lithe-IDEA#1976(Core9425469,即 #55 + #56 在 Core main 上的提交),插件包来自 main8595a25。TestOfficialGoPluginDebugsEachProjectOfAWorkspaceWithDelve和TestOfficialGoPluginBuildsAndServesAModule都通过。docs/feature-matrix.md的“最近验证”和e2e/host/lithe-host.json的宿主固定版本,等 #1976 合入后另开 PR 更新。