Skip to content

refactor(lsp-engine): 索引排除改由语言服务器声明 indexingExclusions,Core 不再识别 rust-analyzer 和 gopls - #68

Merged
xiaoyumuxi merged 1 commit into
mainfrom
refactor/1856-indexing-exclusions
Nov 16, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
refactor/1856-indexing-exclusions

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

关联 Issue / Linked issue

#1856 要求把 Core 里剩下的 5 类语言专属默认值移出 Core。本 PR 只做第 2 项(rust-analyzer / gopls 的索引排除)。第 5 项在 #66;第 1、3、4 项(忽略目录、go/node 运行时、运行发现)不在本 PR,#1856 保持打开。

PR 类型 / Type

  • fix:缺陷修复(去掉 Core 里的语言特判;声明了的服务器行为与原来一致,见下方“复现与根因”)

改动说明 / What changes

背景 / Why

用户把目录排除在索引之外(或打开“排除 Git 忽略的目录”)后,LSP 引擎要把这些目录告诉语言服务器,否则服务器照样索引它们。原来的 lsp-engine/src/scan_settings.rs 按 provider 名字分支:

  • rust → 写进 rust-analyzer.files.exclude,字面路径;
  • go → 写进 gopls.directoryFilters,-<路径> 形式,根目录写 -,没有数组时先补默认的 -**/node_modules,名字带通配符的目录跳过。

这是 Core 认识具体语言服务器的写死逻辑,违反“Core 对语言和工具零特判”。其他语言的服务器拿不到这个能力,除非再往 Core 里加分支。

改动 / Changes

新声明 languageServers[].indexingExclusions(plugin-language-servers,新文件 indexing_exclusions.rs)

字段 含义
section 工作区配置里数组的点分路径,最多 8 个键
entry 一项的写法,恰好一个 ${path}
rootEntry? 工作区根目录的写法
default? 配置里没有该数组时服务器的默认值,最多 32 项
pathSyntax? literal(默认)或 glob;glob 时名字含 * ? [ ] { } 的目录不写入

文本字段最多 256 字节、不含控制字符;违反时 plugin.manifest.invalid,字段 languageServers[<n>].indexingExclusions.<field>。它挂在 SessionDeclaration 上(会话字段),所以不需要后端也能声明。

传递路径不变

  • SessionDeclaration::policy() 把声明放进启动计划的 sessionPolicy。桌面端本来就把 sessionPolicy 当 json.RawMessage 原样交给 lsp.startServer,所以桌面端不需要改代码,以后只升级 PINNED_CORE_REVISION。
  • plugin-server-policy:SessionPolicy 接受 indexingExclusions,并用同一套规则复核(lsp.startServer 是公开命令)。
  • lsp-engine:RuntimeSession 保存声明;plugin_configuration() 只按声明把排除目录追加进服务器读到的配置。scan_settings.rs 删掉 "rust" | "go" 分支,只保留通用的“沿点分路径规整、追加、已存在的项移到末尾”逻辑。没有声明的服务器配置原样返回。
  • 原来针对 rust-analyzer、gopls 的单元测试改为用两份等价声明(字面路径 / glob)跑同样的断言,新增“没有数组时从 default 开始、根目录用 rootEntry”的断言。indexing_cold_start_resolves_git_before_provider_initialization 改成用一个虚构的 io.example.server 分别跑 glob 和字面路径两种声明,并断言没有声明时配置不变。

契约

  • contract/v1/README.md:语言服务器字段表加一行;新增 “Indexing exclusions” 小节;sessionPolicy 说明加上 indexingExclusions。“Core 从不按语言 ID、服务器 ID 或工具名分支”这句话现在名副其实。
  • plugin-manifest.schema.json:加 indexingExclusions 及 $defs/indexingExclusionLiteral。
  • fixture:language-system-command.plugin.json(gopls)加上与原写死逻辑等价的声明,command-plans.json 的对应计划带上它;invalid-manifests.json 加 4 个拒绝用例(entry 没有 ${path}、section 有空键、default 带模板、pathSyntax 不认识)。
  • reference/domains/languages.md 中英两节、capabilities-and-versions.md、protocol-changelog.md 同步。

发布顺序与过渡期 / Rollout

旧宿主的 LanguageServerDeclaration 是 deny_unknown_fields,不认识 indexingExclusions,会拒绝带它的清单(已用同样的 serde 结构确认:unknown field indexingExclusions)。所以顺序是:

  1. 本 PR 合入 Core main;
  2. 桌面端把 PINNED_CORE_REVISION 升到合入后的 commit 并发布;
  3. Go 插件在 languageServers[0] 加上与 fixture 相同的声明并发版(Draft:https://github.com/Lithe-IDEA/lithe-plugin-go/pull/17),同时把 e2e/host/lithe-host.json 的宿主固定版本升到第 2 步的 commit。

第 2 步到第 3 步之间,装旧版 Go 插件(1.0.1)的用户,gopls 拿不到排除目录,会照常索引被排除的目录。这只影响 gopls 的索引范围和资源占用:宿主照常不向它发送被排除目录里的文档、诊断和文件变化。仓库里没有 Rust 语言服务器插件,rust-analyzer 这条没有需要补的声明。

不在本 PR 范围内 / Out of scope

  • #1856 第 1、3、4 项。
  • 桌面端固定版本升级(无代码改动)和 Go 插件的声明,按上面的顺序在合入后做。

类型专属:fix

复现与根因

  • 复现步骤、实际结果、期望结果:插件为非 Go、非 Rust 语言声明的服务器,在用户排除目录后仍然索引这些目录;期望服务器能声明自己的排除设置,由宿主填充。
  • 根因:排除设置的键和写法写死在 Core 里,只认 rust、go。
  • 影响平台:macOS、Windows(同一个 Viva 桌面端)。

检查项

  • 回归测试:scan_settings 单测和 indexing_cold_start_resolves_git_before_provider_initialization 覆盖两种声明和“未声明不改配置”;新增 indexing_exclusions 的 3 个单测覆盖填充顺序、glob 过滤、全部校验边界。
  • 行为等价:gopls fixture 的声明对同样的输入产出与原写死逻辑相同的数组(-**/node_modules、-、-vendor、带通配符的目录跳过),由单测断言。
  • 已搜索 scan_settings、provider 分支的全部调用方:只有 RuntimeSession::plugin_configuration()。
  • 另一平台:Viva 桌面端是 macOS 和 Windows 共用的同一份代码。
  • 只改了去掉这个特判所需的代码。

范围检查 / Scope checks

插件契约 / Plugin contract

  • 改了 shared/plugins/contract/v1/:README、schema、fixture 都在本 PR;协议更新记录已登记(languageServers 0 内的补充,API-25)。
  • 只加一个可选字段,不需要新能力版本;没有新增宿主方法或通知。

逻辑归属 / Logic placement

  • Core 只保留通用的“按声明填充配置数组”;哪个键、怎么写由插件声明。Core 里不再出现 rust-analyzer、gopls 的设置名。

无用代码与重构 / Dead code and refactoring

  • scan_settings 里按 provider 分支的代码和只服务于它的辅助逻辑已删除。

其他组(功能矩阵、UI、日志、i18n、性能、设置、发行包):N/A,Core 这边没有涉及。


验证 / Verification

命令或操作 平台 结果
cargo fmt --check macOS arm64 通过
cargo test -p lithe-plugin-language-servers -p lithe-plugin-server-policy -p lithe-plugin-manifest -p lithe-lsp-engine macOS arm64 通过(lsp-engine 174 个)
cargo test -p lithe-core macOS arm64 通过(821 个,含 invalid-manifests 与 command-plans fixture)
cargo clippy --workspace --all-targets --features lithe-remote/server -- -D warnings macOS arm64 通过
bash scripts/rust-core/verify-rust-core-comments.sh macOS arm64 通过
node scripts/rust-core/verify-platform-tests.mjs macOS arm64 通过(52 个 crate)
node shared/plugins/scripts/verify-docs.mjs macOS arm64 通过
node scripts/rust-core/affected-crates.mjs --base origin/main macOS arm64 Linux:--workspace;macOS、Windows:lithe-platform 一组
桌面端 1lck/Lithe-IDEA main(cad565600):LITHE_CORE_RUST_DIR=<本分支> scripts/desktop/desktop-go.sh test -count=1 ./internal/core macOS arm64 通过
同上,./internal/pluginbackend ./internal/marketplace ./internal/pluginservice ./internal/workbench(在 1lck/Lithe-IDEA#2036 的分支上跑,这几个包与该分支的改动无关) macOS arm64 通过
Go 插件 Draft #17 的宿主 e2e:LITHE_CORE_RUST_DIR=<本分支> node scripts/e2e-host.mjs --ref cad5656005288a7ef5897abd9d15494d2faf2fde,插件包带 indexingExclusions macOS arm64 通过(projectgen 5 个、workbench 2 个;带新字段的清单被接受,gopls 诊断和 gofumpt 设置照常生效)

未能执行的检查和原因: 完整 cargo test --workspace 由 Draft 的 Linux CI 运行。Windows 没有在本机执行,由 ready 后的 CI 覆盖。上面的 e2e 临时模块里没有被排除的目录,directoryFilters 的内容由本 PR 的单元测试断言。

提交前确认 / Final checks

  • 分支从最新的 main(957a349)创建,目标分支 main
  • 以 Draft 提交
  • 没有无关改动和构建产物
  • 没有启动 Lithe 应用

…-analyzer 和 gopls

LSP 引擎原来按 provider 是 rust 还是 go 决定把排除目录写进
rust-analyzer.files.exclude 还是 gopls.directoryFilters,以及怎样写。
现在语言服务器在清单里声明 indexingExclusions(section、entry、rootEntry、
default、pathSyntax),启动计划的 sessionPolicy 带上它,引擎只按声明把
排除目录追加进服务器读到的配置;没有声明的服务器配置不变。

- plugin-language-servers:新增 IndexingExclusions 及校验,挂在会话字段上
- plugin-server-policy:SessionPolicy 接受并复核 indexingExclusions
- lsp-engine:scan_settings 去掉按语言的分支,改为按声明填充
- 契约:README、schema、fixture、invalid-manifests、languages 参考页、
  能力对照和协议更新记录

Refs 1lck/Lithe-IDEA#1856
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