Skip to content

feat(toolchain): 工具定义的版本探针可以用子命令开头 - #52

Merged
xiaoyumuxi merged 2 commits into
mainfrom
feat/toolchain-version-subcommand
Nov 15, 2026
Merged

xiaoyumuxi merged 2 commits into
mainfrom
feat/toolchain-version-subcommand

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

背景

Go 插件要在「新建项目」里加一个像 GoLand 那样的 GOROOT 下拉框:列出本机装的 Go,go.mod 的 go 版本默认取选中的那个 Go。这要靠项目生成器的 tool 字段,而 tool 字段的候选来自插件的 toolDefinitions。

工具定义的版本探针 version.arguments 原来要求每个参数都是选项(-x、--x)。Go 只能用 go version 打印版本,go -version、go --version、go -v 都会失败,所以 Go 插件写不出工具定义。Zig(zig version)等工具也是这样。Core 给宿主托管的 go 运行时用的探针本来就是 ["version"](build::invocation::host_runtime_version_arguments),只是工具定义这边不允许。

改动

  • rust/crates/toolchain/src/definitions.rs:version.arguments 的第一个参数可以是选项,也可以是子命令;从第二个参数起只能是选项,否则以 plugin.manifest.invalid(字段 version.arguments)拒绝。单词规则不变:ASCII 字母开头,只含字母、数字和 -,不带 =值,最长 64 字节,1 到 8 个且不重复。原来就拒绝的 ["-c", "script"] 现在照样拒绝,因为 script 不在第一个位置。抽出 probe_word、probe_flag 两个函数。
  • plugin-manifest.schema.json(toolchainVersion.arguments):用 prefixItems 让第一项允许子命令,其余项仍是选项的正则;补上 uniqueItems 和说明。
  • contract/v1/toolchains/README.md:写明 version 的形状和参数规则,以及为什么第一个之后不允许裸词。
  • reference/domains/toolchains.md:中英两节各补一段同样的说明。
  • reference/protocol-changelog.md:时间线加一行(toolDefinitions 0 内的补充,不加能力版本)。
  • 测试 rust/crates/core/src/tests/toolchain_definitions.rs,新增 a_version_probe_may_lead_with_a_subcommand_followed_only_by_flags:
    • 接受 ["version"]、["version", "--json"]、["-version"]、["--version", "-v"];
    • 拒绝 ["version", "script"]、["--version", "run"]、["-c", "script"]、["./version"]、["version=1"];
    • validate_declarations 和整份清单校验 validate_manifest_value 两条路径都覆盖。

不涉及宿主方法;桌面端宿主的探针原样传参数(desktop/internal/toolchain/scan.go、probe.go),不用改。

原计划编号 方法 用途
API-23 — 工具定义 version.arguments 校验放宽,不新增方法

验证

命令 平台 结果
cargo test -p lithe-core toolchain_definitions macOS arm64 17 个通过(含新增 1 个)
cargo test -p lithe-toolchain macOS arm64 通过
cargo clippy -p lithe-toolchain -p lithe-core --all-targets -- -D warnings macOS arm64 无警告
cargo fmt --all -- --check macOS arm64 通过
node shared/plugins/scripts/verify-docs.mjs macOS arm64 通过

没做的验证: 本机没有 JSON Schema 校验器,schema 里 prefixItems 加 items 的写法(2020-12 语义:items 只约束 prefixItems 之后的项)是人工核对的,没有用校验器跑过。

合入后

  • 桌面端把 scripts/desktop/build-desktop-core.sh 的 PINNED_CORE_REVISION 升到合入提交。
  • Go 插件(Lithe-IDEA/lithe-plugin-go)再加 go 工具定义和 GOROOT 字段。

Go 只能用 go version 打印版本,原来的校验要求每个探针参数都是选项,
工具定义写不出 Go。现在第一个参数可以是子命令,之后的参数仍然只能是选项,
探针仍然不能把脚本或文件交给工具。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant