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
34 changes: 30 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Release

# Push a tag v<version> matching plugin.json to publish a GitHub Release.
# Lithe Store's tracker picks up the release and opens an index pull request.
# Lithe Store's tracker picks up stable releases and opens index pull requests.
# Tags listed in PRERELEASE_TAGS below are published as pre-releases, which the
# tracker skips; they need a manually submitted Store entry. Keep the plain
# v<version> tag. docs/releases/<tag>.md, when present, lists the changes.
on:
push:
tags: ["v*"]
Expand All @@ -19,17 +22,40 @@ jobs:
with:
node-version: 22
- name: Build archive
run: node scripts/package.mjs --expect-tag "$GITHUB_REF_NAME" | tee "$RUNNER_TEMP/checksums.txt"
run: |
set -o pipefail
node scripts/package.mjs --expect-tag "$GITHUB_REF_NAME" | tee "$RUNNER_TEMP/checksums.txt"
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
# v0.0.1 follows plugin contract v0, which only the new desktop
# client installs, and that client ships as desktop-v* pre-releases.
PRERELEASE_TAGS: v0.0.1
run: |
prerelease=false
for tag in $PRERELEASE_TAGS; do
if [[ "$tag" == "$GITHUB_REF_NAME" ]]; then prerelease=true; fi
done
{
echo "安装:在 Lithe 的插件市场(已预置 Lithe Store 社区源)搜索 Go Support。"
echo "兼容性:按插件契约 v0(schemaVersion 0、pluginAPIVersion 0)编写,需要新版 Lithe 桌面端(desktop-v* 预发布)。旧版 macOS Lithe 无法安装。"
echo
if [[ -s "docs/releases/$GITHUB_REF_NAME.md" ]]; then
cat "docs/releases/$GITHUB_REF_NAME.md"
echo
fi
if [[ "$prerelease" == true ]]; then
echo "安装:预发布版本,Lithe Store 自动追踪会跳过,暂不收录 Store。下载下面的 ZIP,在 设置 → 插件 中点击页面标题栏右侧的 从文件安装…,选中 ZIP 后核对 SHA-256 并确认。"
else
echo "安装:Lithe Store(https://github.com/Lithe-IDEA/Lithe-store)中的 Go Support 条目合并后,可在 设置 → 插件 → 插件市场 中搜索 Go Support 并安装。"
fi
echo
echo "SHA-256:"
echo '```'
sed 's#^dist/##' "$RUNNER_TEMP/checksums.txt"
echo '```'
} > "$RUNNER_TEMP/notes.md"
gh release create "$GITHUB_REF_NAME" dist/*.zip --title "Go Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md"
release_flags=()
if [[ "$prerelease" == true ]]; then
release_flags+=(--prerelease)
fi
gh release create "$GITHUB_REF_NAME" dist/*.zip --title "Go Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}"
131 changes: 87 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,124 @@
# Go Support for Lithe

为 [Lithe](https://github.com/1lck/Lithe-IDEA) 提供 Go 代码智能、运行 Go 文件和 `go test`。
这是一个通过 [Lithe Store](https://github.com/Lithe-IDEA/Lithe-store) 分发的**社区插件**;
它由原先的官方插件 `dev.lithe.plugin.go-support` 迁移而来,功能声明保持不变。
为 [Lithe](https://github.com/1lck/Lithe-IDEA) 提供 Go 支持:用你电脑上的 `gopls` 提供代码智能,
用声明式构建系统接口(`buildSystems`)识别 Go 模块,在构建窗口里列出包,运行 `go build`、`go vet`、
`go test` 和 `go run`,查看模块依赖。
这是一个**社区插件**,按插件契约 v0 编写。插件只有一份 `plugin.json`,不附带任何可执行文件,也没有后端进程。

> English: Go language intelligence through your own `gopls`, plus running Go files and `go test`, for Lithe.
> English: Go support for Lithe — code intelligence through your own `gopls`, and the Go Modules build system
> (package model, build, vet, test, run and the module list) through the declarative `buildSystems` contract.
> The plugin is a single `plugin.json` with no executables and no backend process.

> **预发布**:按插件契约 v0(`schemaVersion: 0`、`pluginAPIVersion: 0`)编写,只能装进新版 Lithe 桌面端
> (`desktop-v*` 预发布),旧版 macOS Lithe 无法安装。

## 功能

| 功能 | 依赖的程序 |
| 功能 | 说明 |
| --- | --- |
| 补全、跳转定义、悬停提示、诊断 | 你电脑上的 `gopls` |
| 运行当前 `.go` 文件、`go test`(整个工作区、当前目录、单个测试) | 项目使用的 `go` 工具链 |
| 代码智能 | 补全、跳转定义、悬停、诊断、格式化,由 `gopls` 提供 |
| 识别模块 | 含 `go.mod` 的目录是构建根;`go list -json ./...` 的结果组成模块和包 |
| 构建 | Build(`go build ./...`)作用于模块;Vet(`go vet`)可作用于模块或单个包 |
| 运行 | 每个 `main` 包在构建窗口里有「运行 <包名>」按钮,执行 `go run <导入路径>`,输出显示在构建输出里 |
| 测试 | `go test` 作用于模块或单个包,可用 `-run` 只跑一个测试;输出显示在构建输出里,插件不提供测试报告文件 |
| 诊断 | 把 `文件:行:列: 消息` 形式的编译输出显示为问题 |
| 依赖 | `go list -m -json all` 列出模块依赖(含版本和是否间接依赖) |
| 同步 | `go.mod`、`go.sum`、`go.work` 变化后重新读取模块 |

插件本身只有一份 `plugin.json`,不附带任何可执行文件。安装时 Lithe 会弹窗列出以上程序,确认后才会安装。
## 设置和构建选项

## 安装
**插件设置**(设置 → 插件 → Go Support →「设置」):

1. 安装 Go 和 gopls:
| 设置 | 生效方式 | 说明 |
| --- | --- | --- |
| Go executable | 重新读取模块 | 读取模块、构建、检查、测试和运行用的 `go`。留空时使用 `PATH` 里的 `go`。也显示在「构建、执行、部署 › Go Modules」页 |
| Staticcheck analyses | 立即 | 让 gopls 额外报告 staticcheck 的检查结果;大模块上更耗 CPU 和内存 |
| Format with gofumpt | 立即 | 格式化时使用 gofumpt 的更严格规则 |
| Parameter placeholders in completion | 立即 | 补全函数调用时插入参数占位符 |
| Hover documentation | 立即 | 悬停显示多少文档:完整、第一句、一行或只有签名 |

```bash
brew install go
go install golang.org/x/tools/gopls@latest
```
后四项通过 `workspace/configuration` 发给正在运行的 gopls,不需要重启语言服务器;
它们也显示在「语言与框架 › Go」页。

2. 在 Lithe 中打开 **设置 → 插件 → 插件市场**,搜索 “Go Support”,安装并确认。
3. 按界面提示重启 Lithe,再打开项目中的 `.go` 文件以激活语言服务器。
**构建选项**(构建窗口 →「构建选项」),只对当前工作区生效:

Lithe 已预置 Lithe Store 社区插件源。如果你之前移除了它,先在 **⚙ → 管理插件仓库…** 中重新添加
`https://github.com/Lithe-IDEA/Lithe-store`。
| 选项 | 传给 go 的内容 |
| --- | --- |
| Build Tags | `-tags <值>` |
| Race Detector | `-race` |

### 从官方 Go Support 迁移
选项会加到构建、检查、测试和运行的命令里。

之前装过官方 Go Support(`dev.lithe.plugin.go-support`)的话,Lithe 的插件管理会把它标成“已迁移到社区插件”。
先卸载旧插件,再按上面的步骤安装本插件。两者声明的语言相同,不要同时启用。
## 依赖的程序

## 本地打包
| 程序 | 用途 | 查找方式 |
| --- | --- | --- |
| `go` 1.21 或更新版本 | 读取模块、构建、检查、测试、运行、依赖 | 插件设置 Go executable;留空时找 `PATH` 里的 `go` |
| `gopls` | 代码智能 | `PATH` 里的 `gopls` |

需要 Node.js 22+ 和 `zip`:
安装插件时 Lithe 会列出这些程序和插件需要的权限(启动语言服务器、运行构建命令),确认后才会安装。
没有这两个程序的话可以先安装:

```bash
node scripts/package.mjs
brew install go
go install golang.org/x/tools/gopls@latest
```

输出 `dist/go-support-<版本>-darwin.zip`(同时适用 Apple Silicon 与 Intel Mac)和它的 SHA-256。
`go install` 把 gopls 装在 `$(go env GOPATH)/bin`,这个目录需要在 Lithe 能看到的 `PATH` 里。

## 安装

1. 从 [Releases](https://github.com/Lithe-IDEA/lithe-plugin-go/releases) 下载 `go-support-<版本>-darwin.zip`。
2. 在 Lithe 中打开 **设置 → 插件**,点击页面标题栏右侧的 **从文件安装…**,选中这个 zip,核对 SHA-256 和权限后确认。
3. 打开含 `go.mod` 的项目。构建窗口会出现 Go Modules,打开 `.go` 文件时启动 gopls。

一个包同时支持 Apple Silicon 和 Intel Mac。

## 工作方式

- 读取模块、构建、检查、测试、运行和依赖都是 `plugin.json` 里声明的 `go` 命令,由 Lithe 解析 `go` 并运行。
- 运行入口由 Lithe 从模型里的 `main` 包生成:每个带 `application` 标签的包一条,名称是导入路径的最后一段。
- gopls 由 Lithe 按 `languageServers` 的声明启动,插件设置通过 `workspaceConfiguration` 里的
`${setting:<id>}` 传给它。
- 插件目录在运行时保持只读。

## 诊断日志

在启用结构化日志 v2 的 Lithe macOS preview 中,宿主按语言服务身份将 gopls 的生命周期、
`window/logMessage` 和有界 stderr 诊断送入当前会话的 `lsp/go` 通道。
插件通过现有 stdio 启动声明复用这条链路,不额外创建日志文件或后台进程。
`go run` 与 `go test` 的程序输出仍属于运行/测试控制台,不复制进诊断日志。
插件没有自己的进程,也不发送 `lithe/log`。gopls 由 Lithe 启动,它的启动结果、`window/logMessage`
和有界的 stderr 由 Lithe 记进语言服务的日志;`go` 命令的输出显示在构建输出里,不复制进诊断日志。
排障时使用 Lithe 的日志窗口和诊断导出,不要开启 gopls 的 RPC dump,也不要把源码、环境变量或完整命令行写进日志。

## 本地打包

需要 Node.js 22+ 和 `zip`:

```bash
node scripts/package.mjs
```

gopls 由插件声明、宿主执行,插件没有自己的进程发送 `lithe/log`。宿主因此替插件把每次启动尝试
记成与 SDK 插件同一组的操作事实,写入 `plugins/io.github.lithe-idea.go-support/host` 通道,
操作名为 `languageServer/start`:`initialize` 成功记 `plugins.operation.finished`(INFO,含耗时);
失败记 `plugins.operation.failed`(ERROR),失败码只取自启动阶段——`host.executableUnavailable`
(无法解析 gopls 启动命令)、`host.launchFailed`(进程拉起失败)、`host.exitedEarly`(就绪前退出)、
`host.initializeFailed`(初始化握手失败)、`host.timedOut`(初始化超时)。取消、停止和被新启动取代的
尝试不记录;事实不含 gopls 输出、路径或命令行。插件不需要任何日志代码,宿主实现见
https://github.com/1lck/Lithe-IDEA/pull/1720。
输出 `dist/go-support-<版本>-darwin.zip` 和它的 SHA-256。本地开发时,用 **设置 → 插件 → 从文件安装…**
选择这个 zip 安装。

排障时使用 Lithe 的独立日志窗口和诊断导出;需要更多语言服务证据时临时启用详细诊断。
不要添加 gopls 的 RPC dump、源码、环境变量或完整命令行作为日志。Windows 的日志实现仍为 v1;
本文没有声明 Windows 已完成 v2 验收。
`plugin.json` 的完整格式见 Rust Core 仓库里的
[插件契约](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/contract/v1/README.md)、
[构建工具接入指南](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/guides/build-tool-integration.md)
和[语言服务器插件生命周期](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/guides/lsp-plugin-lifecycle.md)。

## 发布新版本

1. 修改 `io.github.lithe-idea.go-support/plugin.json` 的 `version`,合入 `main`。
1. 按语义化版本修改 `io.github.lithe-idea.go-support/plugin.json` 的 `version`:只修 Bug 升修订号,
加功能升次版本号,有不兼容的变化升主版本号。合入 `main`。
2. 推送同名标签:

```bash
git tag v0.2.0 && git push origin v0.2.0
git tag v0.0.1 && git push origin v0.0.1
```

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

## 许可

Expand Down
17 changes: 17 additions & 0 deletions docs/releases/v0.0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
0.0.1 是按插件契约 v0 重新发布的首个版本。

功能:
- gopls 代码智能:补全、跳转定义、悬停、诊断和格式化。
- 声明式构建系统 Go Modules:用 `go list -json ./...` 读取模块和包,`go.mod`、`go.sum`、`go.work` 变化后重新读取。
- 构建窗口里的 Build、Vet 任务,编译诊断显示为问题。
- 每个 `main` 包都有「运行 <包名>」入口,执行 `go run <导入路径>`。
- 测试整个模块、单个包或单个测试。
- 用 `go list -m -json all` 列出模块依赖。
- 插件设置 Go executable,以及 gopls 的 Staticcheck analyses、Format with gofumpt、Parameter placeholders in completion、Hover documentation 四项设置。
- 构建选项 Build Tags(`-tags`)和 Race Detector(`-race`)。

权限:`languageServer.launch`、`process.build`。

兼容性:
- 只能装进新版 Lithe 桌面端(`desktop-v*` 预发布),旧版 macOS Lithe 无法安装。
- 本版本是预发布,Lithe Store 的自动追踪会跳过它。
Loading
Loading