Repository navigation
feat: 用 Delve 调试 Go 包,新建项目里加入 Go 模块 - #6
Merged
Merged
Conversation
- debugAdapters[delve]:启动 PATH 里的 dlv dap,传输方式 tcpAnnounced, 从 stdout 读取 DAP 地址公告;program 绑定 target.directory(当前文件所在的包)。 - projectGenerators[go-module]:新建项目左侧的 Go,只写 go.mod、.gitignore 和可选的 main.go,不运行 go mod init,创建时不需要联网或安装 go。 - 插件版本 0.1.0,v0.1.0 发成预发布;新增 l10n/zh-Hans.json 翻译插件设置。 - e2e/host:固定宿主 cebbe0def(1lck/Lithe-IDEA#1958),新增 Delve 调试端到端测试 和生成器集成测试;构建输出改从运行控制台读取。 - 功能矩阵新增 go-debug-delve、go-project-generator。
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 Support 插件一直只有 gopls 代码智能和 Go Modules 构建,用户没法在 Lithe 里调试 Go 程序,「新建项目」里也没有 Go。
Delve 的
dlv dap不支持 stdio,只会自己选一个本机端口监听,再把地址打印到标准输出。宿主原本只支持stdio和tcpLanguageServer两种调试传输,所以要先在宿主和 Core 里补上tcpAnnounced(1lck/Lithe-IDEA#1953):debug.adapters.readAnnouncement判断哪一行是地址公告;新增target.directory绑定,用来调试当前文件所在的包。tcpAnnounced适配器。PWD。项目路径经过符号链接时(macOS 的/var就是),Delve 的go build会报 “outside main module”。这个 PR 修复了它,终端里的同类问题也一起修了。改动
plugin.json(0.0.1 → 0.1.0)requires加入debugAdapters: 0、projectGenerators: 0;permissions加入debug.launch、project.generate;activationEvents加入onDebug:delve。debugAdapters[delve]:「Go (Delve)」,只支持 launch。打开.go文件时可选(file+go语言)。启动PATH里的dlv dap(systemCommand),传输方式为tcpAnnounced,从 stdout 读取以DAP server listening at:开头的hostPort。program绑定target.directory(当前文件所在的包),cwd、args、env分别绑定target.workingDirectory、target.arguments、target.environment。projectGenerators[go-module]:「新建项目」左侧的 Go,排序 30。字段有:${project.name|lower},用正则校验,最长 200);生成步骤只写文件,不运行
go mod init,创建项目不需要联网,也不需要装go。创建后打开main.go;不加示例代码时打开go.mod。templates/go/module/(go.mod、.gitignore,其中.gitignore忽略__debug_bin*)和templates/go/sample/main.go。icons/go-project.svg:新建项目里的 Go 图标,浅色和深色外观下都清楚。l10n/zh-Hans.json:插件设置的中文名称和说明(设置分区和 5 个设置项)。调试适配器名称和新建项目的字段不在插件语言文件覆盖的范围内,这两处暂时只有英文。e2e/host/下:desktop/internal/workbench/official_go_plugin_debug_e2e_test.go,新增TestOfficialGoPluginDebugsAModuleWithDelve:安装发布包,在main.go:7打断点,开始调试后停在main.main并显示局部变量name = "Gopher";Delve 的地址公告不进调试控制台;继续运行后程序输出Hello, Gopher!,会话自动结束,Delve 删除__debug_bin;安装目录逐字节不变。desktop/internal/projectgen/go_integration_test.go:经 Core 的表单、生成计划和宿主执行器,生成带示例代码的模块和空模块;模块路径带空格时表单拒绝。official_go_plugin_e2e_test.go:构建输出改从运行控制台读取(runConsoleText),跟上宿主的变化。lithe-host.json:固定宿主cebbe0def(fix(desktop): 宿主启动的进程和终端用工作目录作 PWD 1lck/Lithe-IDEA#1958 的分支提交,见“合入前”),加入./internal/projectgen包和调试测试,LITHE_PLUGIN_GO_DIR指向插件源目录(生成器集成测试读取模板用)。release.yml:v0.1.0也标为预发布。目前还没有任何桌面端版本带tcpAnnounced。README.md、docs/releases/v0.1.0.md:说明调试和新建项目的用法与限制。docs/feature-matrix.md:新增go-debug-delve、go-project-generator两个条目,更新go-support-plugin的最近验证。日志
插件没有 SDK 进程,所有结果都由宿主观察、交给 Core 记录(Core
rust/logging/events/plugins.json、debug.json):debugAdapter/start)plugins.operation.finished(INFO),适配器可连接时plugins.operation.failed(ERROR):resolve(PATH里没有dlv)、launch、timeout(10 秒内没有公告)、exit(公告前退出)debug.process.started、debug.session.initialized、debug.session.finisheddebug.session.failed、debug.operation.faileddebug.operation.cancelled(DEBUG)dlv dap不加--log,默认不输出日志插件不自己写日志,也没有包装脚本:
dlv失败时以非零状态退出,宿主据此记录。发布
这个 PR 不发版。合入后要不要推
v0.1.0标签、什么时候提交 Store 条目,由维护者决定;release.yml会把v0.1.0发成预发布(Store 自动追踪会跳过预发布)。合入前
lithe-host.json现在固定的是 fix(desktop): 宿主启动的进程和终端用工作目录作 PWD 1lck/Lithe-IDEA#1958 的分支提交。那个 PR squash 合入 preview 后,要把revision改成 preview 上的合入提交,再跑一次node scripts/e2e-host.mjs。验证
node scripts/package.mjsdist/go-support-0.1.0-darwin.zip,SHA-2569d896706f9fce07c975680087282c7d3f8494d2938263b679ac07a30149cfd72checkManifest)ad05fd3的scripts/validate-index.mjs)node scripts/e2e-host.mjs,固定宿主cebbe0def,Go 1.27.4、gopls、Delve 1.27.2 在PATH上TestOfficialGoPluginBuildsAndServesAModule、TestOfficialGoPluginDebugsAModuleWithDelve和internal/projectgen的 3 个生成器测试全部通过,退出码 0dlv、gopls没做的验证:
PATH里没有dlv时的提示、调试子包、单步和表达式求值)没有做。三个条目的 macOS 验证状态都还是pending。resolve、timeout、exit这几种失败没有在本地触发。