diff --git a/README.md b/README.md index 891a18e..b53a693 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ gopls、go 和 dlv 仍然用你电脑上的。 | 设置 | 生效方式 | 说明 | | --- | --- | --- | | Go executable | 重新读取模块 | 读取模块、构建、检查、测试和运行用的 `go`。留空时使用「工具链」选出的 Go(见下)。也显示在「构建、执行、部署 › Go Modules」页 | +| Delve executable | 下次启动调试 | 选择与项目 Go 版本兼容的本机 Delve 可执行文件。留空时先查找 `PATH`,再查找插件记录的安装目录。 | | Staticcheck analyses | 立即 | 让 gopls 额外报告 staticcheck 的检查结果;大模块上更耗 CPU 和内存 | | Format with gofumpt | 立即 | 格式化时使用 gofumpt 的更严格规则 | | Parameter placeholders in completion | 立即 | 补全函数调用时插入参数占位符 | @@ -97,6 +98,10 @@ gopls、go 和 dlv 仍然用你电脑上的。 打开「调试」窗口,适配器选 **Go (Delve)**,打开要调试的 `.go` 文件,在行号旁设好断点后点「开始」。 +Delve 提示 Go 版本不兼容时,可在「设置 → 插件 → Go Support → 设置」明确选择兼容的 **Delve executable**。 +这个设置对本机的 Go 调试生效,Delve 仍会检查 Go 版本。此设置需要支持 `debugAdapters[].launch.executableSetting` +的桌面宿主。较早的宿主会拒绝包含该字段的插件包,可继续使用 Go Support 1.3.1 的已发布包。 + - 调试的是当前文件所在的包:Delve 在这个包的目录里构建它,再在断点处停下。所以要调试 `cmd/server` 的程序, 打开 `cmd/server` 里的任意文件即可。 - 打开的文件夹里可以并排放好几个项目,根目录不需要 `go.mod`:Delve 从包所在的目录往上找它所属的模块。 @@ -273,6 +278,10 @@ LITHE_TEST_GO_PLUGIN_ARCHIVE="$PWD/dist/go-support-1.3.1-darwin.zip" node script Rust Core,`LITHE_CORE_RUST_DIR` 可以指向本地的 Core 检出。`--ref <分支或 commit>` 换一个宿主版本试跑, `--run <正则>` 只跑部分测试。测试用的是宿主内部的测试工具,升级 `lithe-host.json` 的 `revision` 时可能要同步修改测试。 +复测 Go 1.22.12 的兼容性时,将 Delve 1.27.2 放在 `PATH`,设置 +`LITHE_TEST_COMPATIBLE_DELVE` 为 Delve 1.23.1 的绝对路径,再用支持该设置的宿主运行 +`--run '^TestOfficialGoPluginDebugsWithConfiguredDelve$'`。测试使用同一个 Go 模块先验证版本错误,再通过插件设置选择兼容版并验证断点。 + ## 功能矩阵 插件各项能力在 macOS 和 Windows 上的实现与验收状态见 [docs/feature-matrix.md](docs/feature-matrix.md)。 diff --git a/docs/feature-matrix.md b/docs/feature-matrix.md index e0cc53f..b2ed07e 100644 --- a/docs/feature-matrix.md +++ b/docs/feature-matrix.md @@ -87,7 +87,8 @@ gofumpt 设置立即生效,以及工作流结束后安装目录逐字节不变 ## go-debug-delve -**能力**:「调试」窗口里的 Go (Delve) 适配器。Lithe 启动在 Lithe 里安装时记下的或用户 `PATH` 里的 `dlv dap`,读到 Delve 在标准输出打印的 +**能力**:「调试」窗口里的 Go (Delve) 适配器。用户可以在 Go Support 插件设置里指定本机 Delve 程序,下次启动调试时读取。 +留空时,Lithe 先在 `PATH` 中查找 `dlv`,再查找插件记录的安装目录。显式路径无效时调试启动失败。Lithe 启动 Delve 后,读到标准输出打印的 `DAP server listening at: <地址>` 后连接这个本机地址;在当前文件所在的包目录里构建并调试这个包(`dlvCwd` 和 `env.PWD` 绑定到 `target.directory`,`program` 是 `.`), 程序的工作目录也是包目录(`cwd` 绑定到 `target.directory`,不再是调试引擎默认的工作区根目录)。打开的文件夹根目录不需要 `go.mod`,可以并排放多个模块;没有 `go.mod` 的目录以 `GO111MODULE=auto` 构建目录里的全部文件。支持断点、单步、调用栈、变量和表达式求值,程序输出显示在调试控制台,程序结束后会话自动结束。 diff --git a/e2e/host/desktop/internal/workbench/official_go_plugin_debug_e2e_test.go b/e2e/host/desktop/internal/workbench/official_go_plugin_debug_e2e_test.go index 6b14f8e..e8e38f8 100644 --- a/e2e/host/desktop/internal/workbench/official_go_plugin_debug_e2e_test.go +++ b/e2e/host/desktop/internal/workbench/official_go_plugin_debug_e2e_test.go @@ -1,6 +1,8 @@ package workbench import ( + "context" + "encoding/json" "os" "os/exec" "path/filepath" @@ -10,6 +12,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/buildprocess" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginsettings" ) // goDebugWorkspace lays out a workspace like a course folder: the root has no @@ -30,6 +33,82 @@ var goDebugWorkspace = map[string]string{ "scratch/greeting.go": "package main\n\nfunc greeting() string { return \"Loose\" }\n", } +// TestOfficialGoPluginDebugsWithConfiguredDelve uses Go 1.22.12 with Delve +// 1.27.2 on PATH and the absolute path of Delve 1.23.1 outside PATH. +func TestOfficialGoPluginDebugsWithConfiguredDelve(t *testing.T) { + compatible := os.Getenv("LITHE_TEST_COMPATIBLE_DELVE") + archive := os.Getenv("LITHE_TEST_GO_PLUGIN_ARCHIVE") + if compatible == "" || archive == "" { + t.Skip("set LITHE_TEST_GO_PLUGIN_ARCHIVE and LITHE_TEST_COMPATIBLE_DELVE") + } + t.Setenv("GOTOOLCHAIN", "go1.22.12") + versionCtx, cancelVersion := context.WithTimeout(context.Background(), time.Minute) + defer cancelVersion() + for _, check := range []struct { + program, want string + }{ + {"go", "go version go1.22.12 "}, + {"dlv", "Version: 1.27.2"}, + {compatible, "Version: 1.23.1"}, + } { + if out, err := exec.CommandContext(versionCtx, check.program, "version").CombinedOutput(); err != nil || !strings.Contains(string(out), check.want) { + t.Fatalf("%s version = %s, %v; want %s", check.program, out, err, check.want) + } + } + + h := newHarness(t, &testKernel{Client: core.NewClient()}) + previousGrace := buildprocess.StopGrace() + t.Cleanup(func() { buildprocess.SetStopGrace(previousGrace) }) + h.app.refreshStopGrace() + awaitStateWithin(t, h, 20*time.Second, "Core's stop time", func() bool { return buildprocess.StopGrace() > 0 }) + installed := installOfficialPluginArchive(t, h, archive, "io.github.lithe-idea.go-support") + before := packageDigest(t, installed) + h.app.reloadPluginLanguages() + root := t.TempDir() + writePluginFixture(t, root, map[string]string{ + "go.mod": "module example.com/delve\n\ngo 1.22.12\n", + "main.go": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tname := \"Gopher\"\n\tfmt.Printf(\"Hello, %s!\\n\", name)\n}\n", + }) + p := openHostedPanel(t, h, root) + source := filepath.Join(root, "main.go") + h.app.openFileAtPosition(p, source, 6, 0) + awaitStateWithin(t, h, 30*time.Second, "main.go to open", func() bool { + doc := p.selectedDocument(p.docs.group) + return doc != nil && samePath(doc.path, source) + }) + defer h.app.stopDebug(p) + clickNamedWithoutSettling(t, h, h.app.text.Debug.Start) + awaitStateWithin(t, h, time.Minute, "the Delve compatibility failure", func() bool { + return strings.Contains(p.debug.failure+"\n"+strings.Join(p.debug.output, "\n"), + "Go version go1.22.12 is too old for this version of Delve") + }) + h.app.stopDebug(p) + awaitStateWithin(t, h, 30*time.Second, "the failed session to stop", func() bool { + return p.debug.activeSession() == nil && len(debugBinaries(t, root)) == 0 + }) + + settings := pluginsettings.New(h.app.kernel, h.store.Dir()) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + snapshot, err := settings.Load(ctx, p.debug.adapters[0].Manifest, root) + if err != nil { + t.Fatal(err) + } + value, err := json.Marshal(compatible) + if err != nil { + t.Fatal(err) + } + saved, err := settings.Save(ctx, snapshot, "global", []core.PluginSettingEdit{{ID: "delveExecutable", Value: value}}, nil) + if err != nil || !saved.Committed { + t.Fatalf("save global Delve setting: %+v, %v", saved, err) + } + debugGoProgram(t, h, p, root, goDebugProgram{source: "main.go", line: 7, local: `"Gopher"`}) + h.app.closeProject() + awaitStateWithin(t, h, 30*time.Second, "the closed project", func() bool { return h.app.project == nil }) + h.settle() + assertPackageUnchanged(t, installed, before) +} + // goDebugProgram is one program of goDebugWorkspace the test debugs. type goDebugProgram struct { // source is the file, relative to the workspace, the breakpoint goes in. diff --git a/e2e/host/lithe-host.json b/e2e/host/lithe-host.json index 2f017f7..a206e60 100644 --- a/e2e/host/lithe-host.json +++ b/e2e/host/lithe-host.json @@ -1,9 +1,9 @@ { "repository": "https://github.com/1lck/Lithe-IDEA.git", - "revision": "312a9c63a9b2f308457a03cd027e2b9ead789fb0", + "revision": "a51badfe0438b199816220dcd8c3187227ad826b", "packages": { "./internal/projectgen": "^TestGoPlugin", - "./internal/workbench": "^TestOfficialGoPlugin(BuildsAndServesAModule|DebugsEachProjectOfAWorkspaceWithDelve|RunsGoBuildAndGoTestConfigurations|DrawsItsSettingsRegions)$" + "./internal/workbench": "^TestOfficialGoPlugin(BuildsAndServesAModule|DebugsEachProjectOfAWorkspaceWithDelve|DebugsWithConfiguredDelve|RunsGoBuildAndGoTestConfigurations|DrawsItsSettingsRegions)$" }, "requiredEnvironment": { "LITHE_TEST_GO_PLUGIN_ARCHIVE": "go-support--darwin.zip to install, for example dist/go-support-1.3.1-darwin.zip" diff --git a/io.github.lithe-idea.go-support/l10n/zh-Hans.json b/io.github.lithe-idea.go-support/l10n/zh-Hans.json index 0f16f40..46316e6 100644 --- a/io.github.lithe-idea.go-support/l10n/zh-Hans.json +++ b/io.github.lithe-idea.go-support/l10n/zh-Hans.json @@ -6,6 +6,11 @@ "description": "读取模块、构建、检查、测试和运行时使用的 go 程序。留空表示使用 PATH 中的 go。", "placeholder": "自动:PATH 中的 go" }, + "delveExecutable": { + "title": "Delve 程序", + "description": "调试使用的本机 Delve 程序。留空时先在 PATH 中查找 dlv,再查找插件记录的安装目录。", + "placeholder": "自动查找 dlv" + }, "staticcheck": { "title": "Staticcheck 分析", "description": "把 staticcheck 的额外检查结果报告为诊断。大模块上会占用更多 CPU 和内存。" diff --git a/io.github.lithe-idea.go-support/plugin.json b/io.github.lithe-idea.go-support/plugin.json index 7072160..61a1df1 100644 --- a/io.github.lithe-idea.go-support/plugin.json +++ b/io.github.lithe-idea.go-support/plugin.json @@ -53,6 +53,16 @@ }, "section": "Go toolchain" }, + { + "id": "delveExecutable", + "type": "file", + "title": "Delve executable", + "description": "The local Delve program used for debugging. Leave empty to look for dlv on PATH, then in plugin installation directories.", + "default": "", + "placeholder": "Automatic: find dlv", + "effect": "nextRun", + "section": "Go toolchain" + }, { "id": "staticcheck", "type": "boolean", @@ -664,6 +674,7 @@ } }, "launch": { + "executableSetting": "delveExecutable", "process": { "launch": { "kind": "systemCommand",