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
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
> **预发布**:按插件契约 v0(`schemaVersion: 0`、`pluginAPIVersion: 0`)编写,只能装进新版 Lithe 桌面端
> (`desktop-v*` 预发布),旧版 macOS Lithe 无法安装。0.1.0 的调试需要宿主支持 `tcpAnnounced` 调试适配器
> ([1lck/Lithe-IDEA#1954](https://github.com/1lck/Lithe-IDEA/pull/1954)),`go` 工具定义需要固定了 Rust Core
> 6477e9a 或更新版本的桌面端([1lck/Lithe-IDEA#1964](https://github.com/1lck/Lithe-IDEA/pull/1964))。在包含它们的桌面端版本发布前,这个版本只作为预发布提供。
> 6477e9a 或更新版本的桌面端([1lck/Lithe-IDEA#1964](https://github.com/1lck/Lithe-IDEA/pull/1964)),
> 在插件详情里安装 gopls 和 dlv 需要固定了 Core c550c2b 或更新版本、支持 `commandInstallers` 的桌面端
> ([1lck/Lithe-IDEA#1971](https://github.com/1lck/Lithe-IDEA/pull/1971))。在包含它们的桌面端版本发布前,这个版本只作为预发布提供。

## 功能

Expand Down Expand Up @@ -102,20 +104,31 @@ GOROOT 只能选 Go 1.21 或更新的版本;选了更旧的版本时表单会
| 程序 | 用途 | 查找方式 |
| --- | --- | --- |
| `go` 1.21 或更新版本 | 读取模块、构建、检查、测试、运行、依赖 | 插件设置 Go executable;留空时用「工具链」选出的 Go,最后找 `PATH` 里的 `go` |
| `gopls` | 代码智能 | `PATH` 里的 `gopls` |
| `dlv`(Delve,需要有 `dlv dap` 命令,已用 1.27.2 验证) | 调试 | `PATH` 里的 `dlv`;Delve 构建程序时用 `PATH` 里的 `go` |
| `gopls` | 代码智能 | 先找在 Lithe 里安装时记下的目录,再找 `PATH` 里的 `gopls` |
| `dlv`(Delve,需要有 `dlv dap` 命令,已用 1.27.2 验证) | 调试 | 先找在 Lithe 里安装时记下的目录,再找 `PATH` 里的 `dlv`;Delve 构建程序时用 `PATH` 里的 `go` |

安装插件时 Lithe 会列出这些程序和插件需要的权限(启动语言服务器、运行构建命令、启动调试器、创建项目),
确认后才会安装。没有这些程序的话可以先安装:
安装插件时 Lithe 会列出这些程序和插件需要的权限(启动语言服务器、运行构建命令、启动调试器、创建项目、
安装插件所需的命令行工具),确认后才会安装。

`go` 需要自己安装,例如 `brew install go`。gopls 和 dlv 可以在 Lithe 里装:

1. 打开 **设置 → 插件 → 已安装**,选中 Go Support,切到 **功能**。
2. 缺少的程序会在对应能力卡片上显示“未找到 gopls”或“未找到 dlv”,旁边有 **安装** 按钮。
3. 点击后选择安装位置,核对要运行的命令,确认后开始安装,输出显示在对话框里:
- **Lithe 管理的目录**:运行 `go install <包>@latest` 时把 `GOBIN` 设为插件自己的状态目录。
不改动 Go 的默认目录,卸载插件时一起删除。
- **Go 的默认位置**:不设 `GOBIN`,装进 `go env GOBIN`;`GOBIN` 为空时装进 `$(go env GOPATH)/bin`。
卸载插件时不删除这些文件。

两种位置装好的命令都会被记下,之后启动 gopls 和 Delve 时直接用,不需要再改 `PATH`。安装需要联网,
用的是「构建、执行、部署 › 工具链」选出的 Go(打开的项目固定了 Go 时用那一个),需要 1.21 或更新版本。也可以自己在终端安装:

```bash
brew install go
go install golang.org/x/tools/gopls@latest
go install github.com/go-delve/delve/cmd/dlv@latest
```

`go install` 把 gopls 和 dlv 装在 `$(go env GOPATH)/bin`,这个目录需要在 Lithe 能看到的 `PATH` 里。
不调试的话可以不装 dlv。
在终端安装时,`$(go env GOPATH)/bin` 需要在 Lithe 能看到的 `PATH` 里。不调试的话可以不装 dlv。

## 安装

Expand Down
28 changes: 18 additions & 10 deletions docs/feature-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

## go-support-plugin

**能力**:用用户自己的 `gopls` 提供代码智能;用声明式 `buildSystems` 识别 Go 模块,在构建窗口里列出包,
**能力**:用用户自己的 `gopls` 提供代码智能,缺少 gopls 时可以在插件详情的能力卡片上安装;用声明式 `buildSystems` 识别 Go 模块,在构建窗口里列出包,
运行 `go build`、`go vet`、`go test` 和 `go run`,列出模块依赖;插件设置调整 `go` 路径和 gopls 选项。
没有设置 `go` 路径时,构建用 `toolDefinitions` 里的 `go` 工具定义解析 Go:项目固定的 Go、全局默认、`GOROOT`、
`PATH` 里的 `go`、在常见位置找到的最新安装。
Expand All @@ -38,13 +38,15 @@

**证据**:

- `io.github.lithe-idea.go-support/plugin.json`:`languageServers`、`buildSystems`、`settings`、`toolDefinitions` 的声明。
- `io.github.lithe-idea.go-support/plugin.json`:`languageServers`、`buildSystems`、`settings`、`toolDefinitions` 的声明,
以及 `commandInstallers` 里的 `gopls`(`requiresTools` 为 `go`,`commands.install` 权限)。
- `e2e/host/desktop/internal/projectgen/go_integration_test.go`:`TestGoPluginToolDefinitionFindsTheLocalGo`
确认工具定义找到 `PATH` 里那个 go 的 GOROOT 和版本。
- `e2e/host/desktop/internal/workbench/official_go_plugin_e2e_test.go`:宿主端到端测试。

**依赖的宿主能力**:`languageServers`(宿主启动 gopls 并转发 `workspace/configuration`)、`buildSystems`
(构建窗口识别实例、读取模型、运行命令任务和运行入口、运行测试)、`settings`(插件设置页和设置生效方式)。
(构建窗口识别实例、读取模型、运行命令任务和运行入口、运行测试)、`settings`(插件设置页和设置生效方式)、
`commandInstallers`(Lithe-core-rust#53,Core c550c2b;宿主在 1lck/Lithe-IDEA#1971 检测缺少的命令并提供安装按钮)。
宿主 [1lck/Lithe-IDEA@059d878d4](https://github.com/1lck/Lithe-IDEA/blob/059d878d4284e1a1fd218aeaa56c29d9753d4dfa/desktop/internal/pluginhost/pluginhost.go)
的 `pluginhost.go` 开头列出了这些能力的服务范围;语言服务器的 code action、signature help 和 inlay hints
宿主还没有界面,插件声明了也不会显示。
Expand All @@ -53,7 +55,8 @@
`node scripts/e2e-host.mjs` 通过 `TestOfficialGoPluginBuildsAndServesAModule`,覆盖识别 `go.mod`、`go list` 模型和
`application` 目标、Build、Vet、运行入口、Go executable 设置重新读取模型并用于后续构建、gopls 诊断、
gofumpt 设置立即生效,以及工作流结束后安装目录逐字节不变。没有覆盖 `go test`、依赖列表、`go.mod` 变化后重新读取、
构建选项(Build Tags、Race Detector)、缺少 gopls 时的提示,也没有做下面的手工验收。
构建选项(Build Tags、Race Detector)、缺少 gopls 时的提示和安装(第 7 步,`commandInstallers` 声明晚于这次验证),
也没有做下面的手工验收。
这次验证早于构建加入 `go` 工具定义解析(插件 PR “GOROOT 选择”),之后没有重跑这个测试。

**验证方法**(macOS):
Expand All @@ -62,12 +65,14 @@ gofumpt 设置立即生效,以及工作流结束后安装目录逐字节不变
2. 打开含 `go.mod` 的项目:构建窗口出现 Go Modules,列出模块和包,每个 `main` 包有“运行 <包名>”按钮。
3. 运行 Build、Vet、Test(整个模块、单个包、用 `-run` 只跑一个测试)和运行入口,输出显示在构建输出里;
`文件:行:列: 消息` 形式的编译错误显示为问题。
4. 打开 `.go` 文件:gopls 来自用户的 `PATH`,补全、跳转定义、悬停、诊断和格式化可用;修改 gofumpt、
4. 打开 `.go` 文件:gopls 来自在 Lithe 里安装时记下的目录或用户的 `PATH`,补全、跳转定义、悬停、诊断和格式化可用;修改 gofumpt、
Staticcheck、补全占位符、悬停文档设置后立即生效,不需要重启语言服务器。
5. 修改 Go executable 设置后模块重新读取,之后的构建使用新路径;Build Tags 和 Race Detector 构建选项出现在命令里。
清空 Go executable 后,「构建、执行、部署 › 工具链」列出电脑上的 Go;为项目选另一个 Go 后,构建输出里的 `go version` 随之改变。
6. 查看依赖列表(含版本和间接依赖);修改 `go.mod` 后模块重新读取。
7. `PATH` 里没有 gopls 时给出缺失提示,不崩溃。
7. 没有 gopls 时,插件详情「功能」页的语言服务器卡片显示“未找到 gopls”和安装按钮。分别选 Lithe 管理的目录和
Go 的默认位置安装一次:对话框列出 `go install golang.org/x/tools/gopls@latest`,装好后卡片不再提示,
重新打开 `.go` 文件时 gopls 启动;装进 Lithe 管理的目录时 `go env GOPATH` 下的 `bin` 没有新增文件。
8. 禁用插件后 gopls 和运行中的进程退出;插件安装目录在整个过程中不被写入。

**迁移来源**:主仓库 `shared/platform-feature-matrix/features/go-support-plugin.json`
Expand All @@ -78,9 +83,10 @@ gofumpt 设置立即生效,以及工作流结束后安装目录逐字节不变

## go-debug-delve

**能力**:「调试」窗口里的 Go (Delve) 适配器。Lithe 启动用户 `PATH` 里的 `dlv dap`,读到 Delve 在标准输出打印的
**能力**:「调试」窗口里的 Go (Delve) 适配器。Lithe 启动在 Lithe 里安装时记下的或用户 `PATH` 里的 `dlv dap`,读到 Delve 在标准输出打印的
`DAP server listening at: <地址>` 后连接这个本机地址;调试当前文件所在的包(`target.directory` 绑定到 `program`),
工作目录是项目根目录。支持断点、单步、调用栈、变量和表达式求值,程序输出显示在调试控制台,程序结束后会话自动结束。
缺少 `dlv` 时可以在插件详情的能力卡片上安装。

| 平台 | 实现 | 验证 | 说明 |
| --- | --- | --- | --- |
Expand All @@ -89,11 +95,13 @@ gofumpt 设置立即生效,以及工作流结束后安装目录逐字节不变

**证据**:

- `io.github.lithe-idea.go-support/plugin.json`:`debugAdapters` 里的 `delve`,以及 `debug.launch` 权限和 `onDebug:delve` 激活事件。
- `io.github.lithe-idea.go-support/plugin.json`:`debugAdapters` 里的 `delve`,以及 `debug.launch` 权限和 `onDebug:delve` 激活事件;
`commandInstallers` 里的 `dlv`。
- `e2e/host/desktop/internal/workbench/official_go_plugin_debug_e2e_test.go`:宿主端到端测试。

**依赖的宿主能力**:`debugAdapters` 的 `tcpAnnounced` 传输(宿主启动适配器进程,交给 Core 判断哪一行是地址公告,
再连接公告的本机端口)、`target.directory` 绑定(Core a58e07e,Lithe-core-rust#47)。
再连接公告的本机端口)、`target.directory` 绑定(Core a58e07e,Lithe-core-rust#47)、
`commandInstallers`(Core c550c2b,宿主 1lck/Lithe-IDEA#1971)。

**限制**:只支持 launch,不支持 attach 和调试测试;适配器只在打开 `.go` 文件时可选(选择器是 `file` 加 `go` 语言),
从构建窗口的运行入口启动调试还不支持。Delve 在项目根目录生成 `__debug_bin…` 临时程序,会话结束时删除。
Expand All @@ -111,7 +119,7 @@ Go 1.27.4、Delve 1.27.2。`node scripts/e2e-host.mjs` 通过 `TestOfficialGoPlu
3. 程序停在断点:调用栈顶是 `main.main` 和断点所在行,变量里能看到局部变量的值;单步、表达式求值可用。
4. 点「继续」:程序运行到结束,输出显示在调试控制台,会话自动结束,项目根目录里没有留下 `__debug_bin…`。
5. 调试 `cmd/<名字>` 这样的子包:打开该包里的文件后开始,调试的是这个包。
6. `PATH` 里没有 `dlv` 时,开始调试给出缺少程序的提示,不崩溃。
6. 没有 `dlv` 时,插件详情「功能」页的调试器卡片显示“未找到 dlv”和安装按钮;安装后开始调试能停在断点。
7. 整个过程中插件安装目录不被写入。

## go-project-generator
Expand Down
7 changes: 4 additions & 3 deletions docs/releases/v0.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
- 调试:「调试」窗口里的 Go (Delve) 适配器用你电脑上的 `dlv dap` 调试当前文件所在的包,支持断点、单步、调用栈、变量和表达式求值;程序结束后会话自动结束,程序输出留在调试控制台。
- 新建项目:「新建项目」对话框里的 Go 生成 `go.mod` 和 `.gitignore`,可选生成示例 `main.go`;可以选择 GOROOT(从电脑上找到的 Go 里选,默认最新的一个,创建后项目固定使用它),填写模块路径(默认是小写的项目名)和 Go 版本(高级,默认是所选 GOROOT 的版本)。不运行 `go mod init`,创建项目不需要联网;没有找到 Go 时 GOROOT 留空,Go 版本需要手动填写。
- 工具链:插件声明 `go` 工具,Lithe 在 Homebrew、`/usr/local/go`、`~/sdk/go*` 等位置找到 Go 并读出版本,列在「构建、执行、部署 › 工具链」里。没有设置 Go executable 时,构建、检查、测试和运行使用项目固定的 Go,没有固定时依次使用全局默认、`GOROOT`、`PATH` 里的 `go` 和找到的最新安装。
- 安装 gopls 和 dlv:缺少时,插件详情「功能」页的能力卡片显示“未找到 gopls”或“未找到 dlv”和安装按钮。可以装进 Lithe 管理的目录(卸载插件时一起删除),也可以装进 Go 的默认位置(`go env GOBIN`,为空时 `$(go env GOPATH)/bin`);安装用「工具链」选出的 Go 运行 `go install <包>@latest`,需要联网。装好的位置会被记下,不需要再改 `PATH`。
- 插件设置的中文名称和说明(`l10n/zh-Hans.json`)。

权限:新增 `debug.launch`(启动 Delve)和 `project.generate`(新建项目),原有 `languageServer.launch`、`process.build` 不变。
权限:新增 `debug.launch`(启动 Delve)、`project.generate`(新建项目)和 `commands.install`(安装 gopls、dlv,每次安装前都会确认),原有 `languageServer.launch`、`process.build` 不变。

依赖的程序:调试需要 `PATH` 里的 `dlv`(`go install github.com/go-delve/delve/cmd/dlv@latest`);不调试可以不装。
依赖的程序:代码智能需要 `gopls`,调试需要 `dlv`,都可以在插件详情里安装,也可以自己用 `go install` 装进 `PATH`;不调试可以不装 dlv。

兼容性:
- 需要固定了 Rust Core 6477e9a 或更新版本、并能启动 `tcpAnnounced` 调试适配器的桌面端(1lck/Lithe-IDEA#1954、1lck/Lithe-IDEA#1964)。更早的桌面端会拒绝安装本版本:它的 Core 不认识调试配置里的 `target.directory` 绑定(Core a58e07e 起支持),也不接受以子命令开头的版本探针 `go version`(Core 6477e9a 起支持)。
- 需要固定了 Rust Core c550c2b 或更新版本、能启动 `tcpAnnounced` 调试适配器并支持 `commandInstallers` 的桌面端(1lck/Lithe-IDEA#1954、1lck/Lithe-IDEA#1964、1lck/Lithe-IDEA#1971)。更早的桌面端会拒绝安装本版本:它的 Core 不认识调试配置里的 `target.directory` 绑定(Core a58e07e 起支持),不接受以子命令开头的版本探针 `go version`(Core 6477e9a 起支持),也不提供 `commandInstallers` 能力(Core c550c2b 起支持)。
- 新建项目的字段名称和调试适配器名称目前只有英文:插件语言文件还不能翻译这两类文字。
- 只能装进新版 Lithe 桌面端(`desktop-v*` 预发布),旧版 macOS Lithe 无法安装。
- 本版本是预发布,Lithe Store 的自动追踪会跳过它。
2 changes: 1 addition & 1 deletion e2e/host/lithe-host.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"repository": "https://github.com/1lck/Lithe-IDEA.git",
"revision": "b03dbf0c02117f0d56b1a430e0d40b347ba9ddcc",
"revision": "a9bddd922e28b4f4dcda4e92b581cbbe7b0f4eb7",
"packages": {
"./internal/projectgen": "^TestGoPlugin",
"./internal/workbench": "^TestOfficialGoPlugin(BuildsAndServesAModule|DebugsAModuleWithDelve)$"
Expand Down
83 changes: 83 additions & 0 deletions io.github.lithe-idea.go-support/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
"pluginAPIVersion": 0,
"requires": {
"buildSystems": 0,
"commandInstallers": 0,
"debugAdapters": 0,
"languageServers": 0,
"languages": 0,
"projectGenerators": 0,
"settings": 0,
"toolDefinitions": 0
},
"requiresTools": [
"go"
],
"vendor": {
"id": "io.github.lithe-idea",
"displayName": "Lithe Community",
"signatureRequirement": "none"
},
"permissions": [
"commands.install",
"debug.launch",
"languageServer.launch",
"process.build",
Expand Down Expand Up @@ -753,5 +758,83 @@
}
]
}
],
"commandInstallers": [
{
"id": "gopls",
"commands": [
"gopls"
],
"tool": "go",
"minimumVersion": "1.21",
"arguments": [
"install",
"golang.org/x/tools/gopls@latest"
],
"mayUseNetwork": true,
"targets": {
"managed": {
"environment": {
"GOBIN": "${installDirectory}"
}
},
"toolDefault": {
"directory": [
{
"arguments": [
"env",
"GOBIN"
]
},
{
"arguments": [
"env",
"GOPATH"
],
"pathList": true,
"append": "bin"
}
]
}
}
},
{
"id": "dlv",
"commands": [
"dlv"
],
"tool": "go",
"minimumVersion": "1.21",
"arguments": [
"install",
"github.com/go-delve/delve/cmd/dlv@latest"
],
"mayUseNetwork": true,
"targets": {
"managed": {
"environment": {
"GOBIN": "${installDirectory}"
}
},
"toolDefault": {
"directory": [
{
"arguments": [
"env",
"GOBIN"
]
},
{
"arguments": [
"env",
"GOPATH"
],
"pathList": true,
"append": "bin"
}
]
}
}
}
]
}
Loading