Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ jobs:
# desktop release has yet.
# v1.0.1 adds the Windows archive on top of 1.0.0 and needs the same host,
# but is published as a stable release so the Store tracker lists it.
PRERELEASE_TAGS: v0.0.1 v1.0.0
# v2.0.0 declares buildSystems runConfigurationTypes (1lck/Lithe-IDEA#2148,
# Lithe-core-rust#94), which no desktop release has yet (desktop-v0.8.5
# pins Core 5c48a67, before #94).
PRERELEASE_TAGS: v0.0.1 v1.0.0 v2.0.0
run: |
prerelease=false
for tag in $PRERELEASE_TAGS; do
Expand Down
46 changes: 41 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

为 [Lithe](https://github.com/1lck/Lithe-IDEA) 提供 Go 支持:用你电脑上的 `gopls` 提供代码智能,
用声明式构建系统接口(`buildSystems`)识别 Go 模块,在构建窗口里列出包,运行 `go build`、`go vet`、
`go test` 和 `go run`,查看模块依赖;用你电脑上的 Delve(`dlv`)调试,在「新建项目」里创建 Go 模块。
`go test` 和 `go run`,查看模块依赖;在「运行/调试配置」里新建 Go 构建和 Go 测试配置;用你电脑上的 Delve(`dlv`)调试,
在「新建项目」里创建 Go 模块。
这是一个**社区插件**,按插件契约 v0 编写。插件只有一份 `plugin.json` 和几份项目模板,不附带任何可执行文件,
也没有后端进程。

> English: Go support for Lithe — code intelligence through your own `gopls`, the Go Modules build system
> (package model, build, vet, test, run and the module list) through the declarative `buildSystems` contract,
> debugging through your own Delve, and a Go module entry in New Project.
> Go Build and Go Test run configurations, debugging through your own Delve, and a Go module entry in New Project.
> The plugin is a `plugin.json` and a few project templates, with no executables and no backend process.

> **兼容性**:按插件契约 v0(`schemaVersion: 0`、`pluginAPIVersion: 0`)编写,只能装进新版 Lithe 桌面端
Expand All @@ -19,7 +20,10 @@
> ([1lck/Lithe-IDEA#1971](https://github.com/1lck/Lithe-IDEA/pull/1971))。1.0.1 起作为正式版本发布并收录到 Lithe Store;
> 没有这些能力的桌面端会从 Store 装到 0.0.1。语言服务器的 `indexingExclusions` 声明需要固定了包含
> [Lithe-core-rust#68](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/68) 的 Core 的桌面端,
> 更早的桌面端不认识这个字段,会拒绝整份清单。
> 更早的桌面端不认识这个字段,会拒绝整份清单。2.0.0 的 Go 构建和 Go 测试运行配置需要支持插件声明运行配置类型的桌面端
> ([1lck/Lithe-IDEA#2148](https://github.com/1lck/Lithe-IDEA/pull/2148),固定了
> [Lithe-core-rust#94](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/94) 的 Core),还没有桌面端发布版本包含它,
> 所以 2.0.0 是预发布版本;更早的桌面端会拒绝安装 2.0.0,继续用 Store 里的 1.0.1。

## 功能

Expand All @@ -30,6 +34,7 @@
| 构建 | Build(`go build ./...`)作用于模块;Vet(`go vet`)可作用于模块或单个包 |
| 运行 | 每个 `main` 包在构建窗口里有「运行 <包名>」按钮,执行 `go run <导入路径>`,输出显示在构建输出里 |
| 测试 | `go test` 作用于模块或单个包,可用 `-run` 只跑一个测试;输出显示在构建输出里,插件不提供测试报告文件 |
| 运行配置 | 「运行/调试配置」的「+」里有 Go 构建(`go run` 一个软件包、文件或目录)和 Go 测试(`go test` 一个软件包或目录,可按模式过滤),可存为项目文件、允许多个实例,见下文“运行配置” |
| 诊断 | 把 `文件:行:列: 消息` 形式的编译输出显示为问题 |
| 依赖 | `go list -m -json all` 列出模块依赖(含版本和是否间接依赖) |
| 同步 | `go.mod`、`go.sum`、`go.work` 变化后重新读取模块 |
Expand Down Expand Up @@ -90,6 +95,36 @@
已经忽略它。
- 目前只支持启动调试(launch),不支持附加到运行中的进程,也不支持调试测试。

## 运行配置

打开「运行/调试配置」,点「+」,选 **Go 构建** 或 **Go 测试**。名称、存为项目文件、允许多个实例、程序参数、
工作目录、环境变量和启动前步骤由 Lithe 统一提供,下面是插件自己的字段:

**Go 构建**:执行 `go run [Go 工具实参] <要运行的内容> [程序参数]`,程序输出显示在 Run 窗口里。

| 字段 | 说明 |
| --- | --- |
| 运行种类 | 软件包、文件或目录,决定下面显示哪一项,默认是软件包 |
| 软件包路径 | main 软件包的导入路径(如 `example.com/app/cmd/server`),或相对工作目录的路径(如 `./cmd/server`) |
| 文件 | main 软件包里的一个 `.go` 文件,`go run` 只构建这个文件 |
| 目录 | main 软件包所在的目录 |
| Go 工具实参 | 放在要运行的内容前面传给 `go run`,例如 `-mod=vendor`、`-race` |

**Go 测试**:执行 `go test [Go 工具实参] [-run <模式>] <软件包或目录> [程序参数]`。

| 字段 | 说明 |
| --- | --- |
| 测试种类 | 目录或软件包,默认是软件包 |
| 软件包路径 | 导入路径,或相对工作目录的软件包模式,默认 `./...`(工作目录下的所有软件包) |
| 目录 | 测试这个目录及其子目录里的所有软件包(传给 go 的是 `<目录>/...`) |
| 模式 | 要运行的测试的正则表达式,作为 `-run` 传入,例如 `^TestName$`;留空运行所有测试 |
| Go 工具实参 | 放在软件包前面传给 `go test`,例如 `-v`、`-count=1` |

文件和目录在项目里存为相对项目根目录的路径,运行时传给 go 的是绝对路径。存为项目文件的配置写在
`.lithe/run/plugin/io.github.lithe-idea.go-support.toml`,可以提交到仓库。两种配置用的 `go` 和构建窗口相同
(见上文“工具链”),构建选项里的 Build Tags 和 Race Detector 也会加进命令。目前还不能调试这两种配置,
调试请用「调试」窗口。

## 新建项目

「新建项目」对话框左侧有 **Go**。可以填写:
Expand Down Expand Up @@ -213,7 +248,7 @@ CI 在 macOS、Windows x64 和 Windows ARM64 上跑这个脚本,Windows 上测

```bash
node scripts/package.mjs
LITHE_TEST_GO_PLUGIN_ARCHIVE="$PWD/dist/go-support-1.0.1-darwin.zip" node scripts/e2e-host.mjs
LITHE_TEST_GO_PLUGIN_ARCHIVE="$PWD/dist/go-support-2.0.0-darwin.zip" node scripts/e2e-host.mjs
```

插件包路径要写绝对路径。脚本把固定版本的宿主(只取 `desktop/` 和 `scripts/`)检出到 `.artifacts/lithe-host`,
Expand All @@ -239,7 +274,8 @@ Lithe 主仓库的功能矩阵不收录插件能力,改动插件行为时在

3. `Release` 工作流会核对标签与版本一致、打包并发布 Release(说明里附 SHA-256 和
`docs/releases/v<版本>.md`)。`release.yml` 里 `PRERELEASE_TAGS` 列出的版本会标为预发布版本:
目前是只能装进新版桌面端的 `v0.0.1`,以及依赖宿主 #1954、#1964、#1971 的 `v1.0.0`;`v1.0.1` 起作为正式版本发布。
目前是只能装进新版桌面端的 `v0.0.1`、依赖宿主 #1954、#1964、#1971 的 `v1.0.0`,以及依赖宿主 #2148 的 `v2.0.0`;
`v1.0.1` 是正式版本。
4. Lithe Store 的自动追踪会发现稳定版本并开合并请求,合并后用户即可在 Lithe 中更新。自动追踪会跳过预发布版本;
需要收录时在 Store 中手工提交条目,并使用已发布 ZIP 的实际 SHA-256。

Expand Down
53 changes: 53 additions & 0 deletions docs/feature-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
| --- | --- | --- | --- | --- |
| `go-support-plugin` | gopls 代码智能、Go Modules 构建、运行与 `go test` | implemented / pending | implemented / pending | 2026-11-15 macOS 宿主端到端测试通过;Windows ARM64、x64 [原生 CI 通过](https://github.com/Lithe-IDEA/lithe-plugin-go/actions/runs/43728078241) |
| `go-debug-delve` | 用用户的 Delve 调试 Go 包 | implemented / pending | partial / pending | 2026-11-15 macOS 宿主端到端测试通过;Windows x64 [原生 CI 通过](https://github.com/Lithe-IDEA/lithe-plugin-go/actions/runs/43728078241);Windows ARM64 上 Delve 不支持 |
| `go-run-configuration-types` | 「运行/调试配置」里的 Go 构建和 Go 测试 | implemented / pending | implemented / pending | 2026-11-18 macOS 宿主端到端测试通过(宿主 a8797ae);Windows 只有命令层面的 `scripts/test.mjs` |
| `go-project-generator` | 「新建项目」里的 Go 模块,GOROOT 选择和 Go 版本默认值 | implemented / pending | implemented / pending | 2026-11-15 macOS 宿主集成测试通过;Windows ARM64、x64 [原生 CI 通过](https://github.com/Lithe-IDEA/lithe-plugin-go/actions/runs/43728078241)(模板生成的模块能构建和测试) |

## go-support-plugin
Expand Down Expand Up @@ -129,6 +130,58 @@ Go 1.27.4、Delve 1.27.2。`node scripts/e2e-host.mjs` 通过 `TestOfficialGoPlu
6. 没有 `dlv` 时,插件详情「功能」页的调试器卡片显示“未找到 dlv”和安装按钮;安装后开始调试能停在断点。
7. 整个过程中插件安装目录不被写入。

## go-run-configuration-types

**能力**:Go 构建和 Go 测试两种运行配置类型,出现在「运行/调试配置」的「+」菜单里,名称、说明、字段标题和选项来自插件的中文翻译。
Go 构建按“运行种类”执行 `go run` 一个软件包(导入路径或相对路径)、一个 `.go` 文件或一个目录;Go 测试执行 `go test`
一个软件包模式(默认 `./...`)或一个目录下的所有软件包(`<目录>/...`),可用“模式”作为 `-run` 过滤。两种都有“Go 工具实参”,
程序参数、工作目录、环境变量、启动前步骤、存为项目文件和允许多个实例由宿主统一提供。存为项目文件时写进
`.lithe/run/plugin/io.github.lithe-idea.go-support.toml`。

| 平台 | 实现 | 验证 | 说明 |
| --- | --- | --- | --- |
| macOS | implemented | pending | 需要支持 `runConfigurationTypes` 的桌面端(1lck/Lithe-IDEA#2148,Core Lithe-core-rust#94);旧宿主不认识这个字段,会拒绝安装本版本 |
| Windows | implemented | pending | 命令与平台无关,文件和目录以绝对路径传给 `go.exe`;还没有在 Windows 版 Lithe 里跑过 |

**证据**:

- `io.github.lithe-idea.go-support/plugin.json`:`buildSystems` 里 `go` 的 `runConfigurationTypes`(`build`、`test`)和
`requires.runConfigurationTypes`;`l10n/zh-Hans.json` 的 `runConfigurationTypes.go`。
- `scripts/test.mjs`:按契约的展开规则把两种类型的字段拼成命令,用真实的 go 运行软件包、文件、目录的 Go 构建,
以及软件包、目录、模式过滤的 Go 测试。
- `e2e/host/desktop/internal/workbench/official_go_plugin_run_types_e2e_test.go`:宿主端到端测试。

**依赖的宿主能力**:`runConfigurationTypes`(API-29,Core Lithe-core-rust#94 的表单、保存和 `build.runConfigurationPlan`;
桌面端 1lck/Lithe-IDEA#2148 的「+」菜单、插件字段和翻译、`.lithe/run/plugin/<ID>.toml`、“允许多个实例”)。

**限制**:

- 不能调试:宿主拒绝调试插件声明的运行类型,调试用「调试」窗口的 Go (Delve)。
- 字段排在宿主的工作目录和环境变量前面,选项是分段按钮而不是下拉框;目录字段不能有默认值,Go 测试的目录不会默认填项目根目录;
名称不会按所选软件包自动生成;类型图标按执行类别显示宿主图标,不显示插件包里的 Go 图标。
- 还没有的字段:输出目录、构建后运行、模拟终端、重定向输入、以 sudo 运行、模块、测试框架、使用所有自定义构建标记。

**最近验证**:2026-11-18,macOS(Apple Silicon),插件 2.0.0 发布包,宿主 `a8797ae`(1lck/Lithe-IDEA main,包含 #2148),
Go 1.27.4。`node scripts/e2e-host.mjs` 通过 `TestOfficialGoPluginRunsGoBuildAndGoTestConfigurations`:两种类型以“Go 构建”
“Go 测试”列出;在对话框里新建 Go 构建,运行种类默认软件包、只显示软件包路径,填 `./cmd/echo` 和程序参数 `one two`
后运行,输出 `echo: one|two`;新建 Go 测试,切到目录后显示目录、隐藏软件包路径,填项目根目录、模式 `^TestGreet$` 和
`-v -count=1` 后运行,只跑了 TestGreet;两条配置都写进插件的运行文档,安装目录逐字节不变。`scripts/test.mjs` 另外用真实的 go
覆盖文件和目录的 Go 构建、软件包模式的 Go 测试。没有覆盖存为项目文件后重新打开项目、允许多个实例、启动前步骤,
也没有做下面的手工验收。

**验证方法**(macOS):

1. 安装插件包,打开含 `go.mod` 的项目,打开「运行/调试配置」点「+」:内置类型之后有 Go 构建和 Go 测试,图标和说明清楚。
2. 新建 Go 构建:运行种类在软件包、文件、目录间切换时只显示对应的一项;三种分别选 `main` 包、`main.go` 和包目录后运行,
程序输出显示在 Run 窗口里,程序参数传给程序;Go 工具实参填 `-race` 时命令里带上它。
3. 新建 Go 测试:默认 `./...` 运行全部测试;改成某个包并填模式后只跑匹配的测试;切到目录后测试这个目录下的所有包;
测试失败时 Run 窗口显示失败和非零退出码。
4. 勾选存为项目文件后,`.lithe/run/plugin/io.github.lithe-idea.go-support.toml` 里有这条配置;关闭并重新打开项目后配置还在,
文件和目录字段仍指向原来的路径。
5. 勾选允许多个实例后连续运行两次,Run 窗口有两个标签;不勾选时第二次运行先停掉第一次。
6. 在构建选项里设 Build Tags 后运行两种配置,命令带上 `-tags`。
7. 整个过程中插件安装目录不被写入。

## go-project-generator

**能力**:「新建项目」对话框里的 Go。GOROOT 下拉列出 `go` 工具定义在电脑上找到的 Go,默认是版本最新的一个,
Expand Down
23 changes: 23 additions & 0 deletions docs/releases/v2.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
2.0.0 在「运行/调试配置」里加入 Go 构建和 Go 测试两种运行配置,并把 gopls 的索引排除改为由清单声明。这个版本需要还没有发布的新版桌面端,所以是预发布版本。

功能:
- Go 构建:点「运行/调试配置」的「+」,选 Go 构建。运行种类可选软件包、文件或目录,执行 `go run`;软件包填导入路径(如 `example.com/app/cmd/server`)或相对路径(如 `./cmd/server`)。“Go 工具实参”放在 `go run` 后面,例如 `-mod=vendor`;程序参数传给程序。
- Go 测试:测试种类可选软件包或目录,执行 `go test`。软件包默认 `./...`;目录会测试它和子目录里的所有软件包;“模式”作为 `-run` 传入,只运行匹配的测试。
- 两种配置都可以存为项目文件(写进 `.lithe/run/plugin/io.github.lithe-idea.go-support.toml`)、允许多个实例,并使用 Lithe 统一的程序参数、工作目录、环境变量和启动前步骤。用的 `go` 和构建窗口相同,构建选项里的 Build Tags 和 Race Detector 也会加进命令。名称、说明和字段有中文翻译。
- 用户排除在索引之外的目录由 Lithe 按清单里的 `indexingExclusions` 写进 gopls 的 `directoryFilters`,不再写死在 Lithe 里。

已知限制:
- 这两种配置还不能调试,调试请用「调试」窗口的 Go (Delve)。
- 插件字段排在工作目录和环境变量前面,运行种类和测试种类显示为分段按钮;Go 测试的目录不会默认填项目根目录,名称不会自动生成。
- 还没有输出目录、构建后运行、模拟终端、重定向输入、以 sudo 运行、模块、测试框架和使用所有自定义构建标记这些选项。

验证:
- 在 macOS 上用包含 1lck/Lithe-IDEA#2148 的桌面端跑宿主端到端测试:在对话框里新建 Go 构建和 Go 测试,运行结果和保存的配置都符合预期,插件安装目录不被写入。
- `scripts/test.mjs` 用真实的 go 运行两种配置拼出的命令,覆盖软件包、文件、目录的 Go 构建和软件包、目录、模式过滤的 Go 测试;CI 在 macOS、Windows x64 和 Windows ARM64 上运行它。
- 还没有在 Lithe 里手工验收,状态见 `docs/feature-matrix.md`。

权限:不变。

兼容性:
- 需要支持插件声明运行配置类型的桌面端(1lck/Lithe-IDEA#2148,固定了 Lithe-core-rust#94 的 Core)。已发布的桌面端 0.8.5 及更早版本都不包含它,会拒绝安装 2.0.0;请继续使用 1.0.1。
- `indexingExclusions` 需要 Lithe-core-rust#68,桌面端 0.8.5 已包含。
42 changes: 21 additions & 21 deletions e2e/host/desktop/internal/workbench/official_go_plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,32 +151,36 @@ func awaitBuildModel(t *testing.T, h *harness, p *project, buildSystemID string,
return instance
}

// runConsoleText is the console of the Run window's shown session, which holds the
// output of the latest execution.
func runConsoleText(p *project) string {
if run := p.activeRun(); run != nil {
return run.output.all()
// awaitExecutionToEnd waits for op to end and returns the console of its Run window session,
// failing unless it succeeded. Runs execute in parallel, so the execution's own session holds
// its output and result, not the window's shown session or its last status line.
func awaitExecutionToEnd(t *testing.T, h *harness, p *project, op *buildOperation, name string, limit time.Duration) string {
t.Helper()
awaitStateWithin(t, h, limit, "the "+name+" execution", func() bool { return !p.build.owns(op) })
session := op.session
if session == nil {
t.Fatalf("%s has no Run window session", name)
}
output := session.output.all()
if session.outcome != runSucceeded {
t.Fatalf("%s did not succeed: outcome=%v summary=%q output=%q", name, session.outcome, session.summary, output)
}
return ""
return output
}

// runBuildTaskToEnd runs one task of the selected instance and waits for it to end.
func runBuildTaskToEnd(t *testing.T, h *harness, p *project, projectID, taskID string, limit time.Duration) string {
t.Helper()
p.build.projectID, p.build.targetID, p.build.taskID = projectID, "", taskID
if _, err := h.app.runBuildTask(p, projectID, "", taskID, nil); err != nil {
op, err := h.app.runBuildTask(p, projectID, "", taskID, nil)
if err != nil {
t.Fatalf("start %s: %v", taskID, err)
}
awaitStateWithin(t, h, limit, "the "+taskID+" task", func() bool { return p.build.operation == nil })
output := runConsoleText(p)
if p.build.status != h.app.text.Build.Succeeded {
t.Fatalf("%s did not succeed: status=%q output=%q", taskID, p.build.status, output)
}
return output
return awaitExecutionToEnd(t, h, p, op, taskID, limit)
}

// runTargetEntryToEnd runs the target's only command Run entry, as its Run button in the
// Build window does, waits for the program to exit and returns the window output.
// Build window does, waits for the program to exit and returns its console.
func runTargetEntryToEnd(t *testing.T, h *harness, p *project, instance *buildInstance, targetID string, limit time.Duration) string {
t.Helper()
entries := buildTargetRunEntries(instance, targetID)
Expand All @@ -185,15 +189,11 @@ func runTargetEntryToEnd(t *testing.T, h *harness, p *project, instance *buildIn
}
entry := entries[0]
h.app.runBuildEntry(p, entry.ID)
if p.build.operation == nil {
op := p.build.runOf("entry:" + instance.ID + "/" + entry.ID)
if op == nil {
t.Fatalf("run %s did not start", entry.Name)
}
awaitStateWithin(t, h, limit, "the "+entry.Name+" run", func() bool { return p.build.operation == nil })
output := runConsoleText(p)
if p.build.status != h.app.text.Build.Succeeded {
t.Fatalf("run %s did not succeed: status=%q output=%q", entry.Name, p.build.status, output)
}
return output
return awaitExecutionToEnd(t, h, p, op, entry.Name, limit)
}

func modelProjectNamed(model core.BuildModel, name string) *core.BuildProject {
Expand Down
Loading
Loading