Skip to content

refactor(core): 拆出领域、LSP 和插件 crate,lithe-core 只留分发器与 FFI - #28

Merged
xiaoyumuxi merged 38 commits into
mainfrom
refactor/core-split-logging-workspace
Nov 14, 2026
Merged

xiaoyumuxi merged 38 commits into
mainfrom
refactor/core-split-logging-workspace

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

关联

这个 PR 做什么

1. lithe-core 只剩分发器和 FFI

origin/main 这个分支
crates/core/src 总行数 180 358 40 583
其中非测试代码 — 6 785
workspace crate 数 12 46

lithe-core 现在只有这些文件:

文件 行数 内容
lib.rs 102 crate 入口、公开再导出
protocol/command.rs、protocol/mod.rs 1 679 请求解析 CoreCommand 和 14 个命令家族子枚举
runtime/dispatcher.rs 731 命令分发入口和不属于任何家族的命令
runtime/dispatcher/*.rs(14 个) 3 454 每个命令家族一个文件,如 git.rs、lsp.rs、plugins.rs
runtime/ffi.rs 297 C ABI
runtime/request_trace.rs 402 请求轨迹
runtime/helper_failures.rs 112 辅助进程失败记录
tests/ 33 798 经分发器跑的端到端命令测试

lsp、plugins 以及各领域模块已从 lithe-core 删除。

2. 新增 34 个 crate

都放在 rust/crates/ 下。代码从 lithe-core 原样搬出,只调整了可见性和导入路径。“内容”一列取自各 crate 的 Cargo.toml description。

crate 行数 依赖的工作区 crate 内容
lithe-diagnostics 9 053 protocol 结构化日志目录、通道、记录、查询,以及有界 Core 事件队列
lithe-text 1 200 protocol UTF-16 位置、文本编辑规划,以及不依赖语言服务器的补全、悬停、跳转和代码片段
lithe-editor 2 422 protocol, text 确定性的编辑器命令:行编辑、注释符、查找、编辑计划、导航历史、偏好、最近文件、恢复决策
lithe-request-context 368 diagnostics 单个请求范围内的状态:来源、轨迹关联,以及有序、已脱敏的宿主事件通道
lithe-workspace 3 568 diagnostics, git-host, protocol, remote, request-context 工作区宿主路由:远程会话和本地或远程文件系统
lithe-git 29 374 ai, core-rules, diagnostics, diff, git-host, github, protocol, remote, request-context, workspace Git 查看、修改和历史
lithe-plugin-model 3 180 protocol 插件清单的共享词汇:拒绝原因、标识、版本、模板、图标、可执行文件、设置、进程、能力版本
lithe-toolchain 4 942 plugin-model, protocol 插件提供的工具链策略:工具定义、目录固定、使用方偏好、解析和版本检查
lithe-vcs 2 204 plugin-model, protocol 统一 VCS 模型:提供者声明、根目录探测、请求规划、回复校验
lithe-execution 4 946 diagnostics, plugin-model, protocol, toolchain, workspace 运行配置:生成、解析、启动环境、项目运行项发现
lithe-debug 14 725 diagnostics, plugin-model, protocol DAP 会话:适配器声明、传输生命周期、调试器模型
lithe-project-generators 3 378 plugin-model, protocol 插件声明的项目生成器:声明、新建项目表单、生成计划、压缩包解压
lithe-build 11 150 debug, execution, plugin-model, protocol, remote, workspace 插件声明的构建系统:校验、静态模型、argv 计划、输出解码
lithe-project 10 167 core-rules, diagnostics, git, protocol, request-context, workspace 项目服务:工作区文件、索引策略、搜索、本地历史、文档渲染
lithe-document-uri 354 protocol 原生路径和 LSP 文档 URI 的词法互转
lithe-lsp-policy 1 107 core-rules, document-uri, protocol 语言工具决策:文档标识、跳转目标、工作区编辑计划、补全合并、激活、问题查询
lithe-lsp-transport 1 935 diagnostics, protocol, remote, workspace 语言服务器进程边界:本地和远程 stdio 启动、Content-Length 分帧,以及给引擎测试用的脚本服务器
lithe-lsp-client 6 290 diagnostics, document-uri, plugin-editor, plugin-keymap-import, plugin-model, plugin-rpc, protocol, text, vcs 有状态 LSP 客户端:能力协商、文档、功能请求,以及服务器提供的各种 provider 协议
lithe-lsp-engine 14 607 diagnostics, document-uri, lsp-client, lsp-transport, plugin-function-relay, plugin-language-servers, plugin-rpc, plugin-server-policy, project, protocol, text, vcs, workspace 语言服务器会话:子进程、请求截止时间、事件队列、插件服务器调用、跨插件函数中转
lithe-plugin-editor 1 604 plugin-model, protocol 插件的编辑器贡献:宿主渲染的编辑器动作,以及后端注册的语言功能 provider
lithe-plugin-grammar 356 plugin-model 插件语言的声明式语法高亮:语法声明和 TextMate 语法解码
lithe-plugin-native-ui 431 plugin-model, protocol 版本化的原生插件界面:有界视图数据、稳定标识、命名动作
lithe-plugin-content-providers 85 plugin-model, protocol 插件后端以 URI scheme 提供的只读文档,以及对每次回复的检查
lithe-plugin-language-servers 746 plugin-model, protocol 插件自带的语言服务器会话:声明的请求、通知、命令、状态保留、启动解析
lithe-plugin-output-links 599 document-uri, plugin-model, protocol, toolchain 插件声明的输出链接匹配器:控制台行匹配并解析到工作区位置
lithe-plugin-backend 115 plugin-model 清单声明的插件后端:每个插件一个长期进程、触发条件、可请求的宿主服务
lithe-plugin-functions 259 plugin-model 清单的 pluginFunctions:插件导出给其他插件的函数,以及它调用的导出函数
lithe-plugin-keymap-import 509 plugin-model, protocol 插件声明的快捷键导入 provider:声明、来源计划、回复校验
lithe-plugin-rpc 2 643 plugin-keymap-import, plugin-language-servers, plugin-model, protocol 插件后端 JSON-RPC:litheFunctions 协商、函数调用、宿主方法和宿主通知目录及授权
lithe-plugin-function-relay 2 028 plugin-functions, plugin-model, plugin-rpc 跨插件函数中转规则:谁能调用哪个导出函数,以及正在进行的调用
lithe-plugin-server-policy 947 document-uri, plugin-language-servers, plugin-rpc, protocol 插件语言服务器的会话策略:准入、闸门、合并命令、操作归属
lithe-plugin-manifest 3 843 build, debug, plugin-backend, plugin-functions, plugin-grammar, plugin-keymap-import, plugin-language-servers, plugin-model, plugin-native-ui, plugin-output-links, plugin-rpc, project-generators, protocol, toolchain, vcs 声明式插件清单:校验、归一化,以及由清单推出的运行、测试、调试、设置和语言服务器计划
lithe-plugin-marketplace 839 plugin-manifest, plugin-model, protocol 插件市场索引:校验、平台和插件 API 过滤、来源 URL 解析、安装审查
lithe-plugin-web-content 1 373 plugin-manifest, plugin-model, protocol 宿主工具窗口里的插件页面:页面内容、可发起的桥接请求、回复和事件的分帧

文件名自然排序(file_names)移到了 lithe-core-rules。

3. 依赖层级

按普通依赖分层,同一层的 crate 互不依赖,可以并行编译:

层 crate
0(8) ai, core-rules, git-host, ide-host, network, process, protocol, remote
1(7) diagnostics, diff, document-uri, github, plugin-model, terminal, text
2(15) debug, editor, lsp-policy, plugin-backend, plugin-content-providers, plugin-editor, plugin-functions, plugin-grammar, plugin-keymap-import, plugin-language-servers, plugin-native-ui, project-generators, request-context, toolchain, vcs
3(3) plugin-output-links, plugin-rpc, workspace
4(6) execution, git, lsp-client, lsp-transport, plugin-function-relay, plugin-server-policy
5(2) build, project
6(2) lsp-engine, plugin-manifest
7(2) plugin-marketplace, plugin-web-content
8(1) core

4. 编译时间

测法:cargo build -p lithe-core --lib,dev profile,10 核 macOS。外部依赖已预先编好,只清掉工作区 crate。两边在同一台机器上依次运行,测量期间没有编辑代码,也没有运行其他编译。

场景 origin/main 这个分支
清空工作区 crate 后全量编译 23.2s 14.7s(−37%)
改动 LSP 客户端(lsp-client/src/client.rs)后增量编译 3.8s 1.2s
改动分发器(core/src/runtime/dispatcher.rs)后增量编译 3.5s 1.3s

这组数字测于第 6 节的文件拆分之前。文件拆分不改变 crate 边界,只影响单个 crate 内部。

5. 拆分时顺手做的整理

  • 统一清单校验:lithe-plugin-model 新增 PluginManifest trait(validate 和 id)。VCS、调试、项目生成器、构建四个领域 crate 的命令改为泛型 cmd::<M>,不再逐个传入校验函数。
  • 删除已退役客户端的遗留:
    • Swift 宿主模型适配器 lsp/languages/swift.rs。LSP 测试改为直接调用生产路径 client_feature_request_canonical。
    • rust/fixtures/modules/built-in-v1.json,以及 application-boundary.md 的 Module Lifecycle Contract 一节。
    • protocol::CoreEvent。
    • agent.json 的 8 个事件,保留 agent 根。
  • hostIntegration 只保留“存在即拒绝”:
    • 语言服务器和构建系统的 hostIntegration 不论取什么值,都以 plugin.integration.unsupported 拒绝,字段路径不变。
    • 删除不可达的集成能力和资源模型、ModelSource/TestResultsSource/DependenciesSource 的 HostIntegration 成员,以及只为它存在的官方插件检查。
  • clippy 清零:整个 workspace 的 clippy 告警清零,两个目标都检查过。没有新增 #[allow]:
    • lithe-lsp-engine 的 runtime_error 改为接收 FailureContext,同时删除 push_issue_log_event。
    • lithe-git 的输出转发收拢为 OutputTarget。
    • 工作区扫描深度原来对空迭代器取 min,这个写法已删除,默认值仍是不限深度。
  • 测试改名:构建插件快照测试改名为 published,去掉过时的 community 措辞。
  • lithe-remote 文档补齐(#1863):公开项全部补上文档注释,verify-rust-core-comments.sh 删掉待补名单,现在每个 crate 都按 missing_docs 检查,没有例外。

6. 文件拆分

超过约 1 500 行生产代码的文件全部按主题拆成子模块。条目原样搬动,只把 super:: 改成 crate::、把跨模块用到的私有项放宽到 pub(crate),不改函数体。剩下最大的手写文件,生产代码在 1 200–1 450 行之间(如 protocol/command.rs、git/src/history.rs)。diagnostics/src/catalog_generated.rs 是生成文件,不拆。

crate 原文件 行数(前 → 后) 拆出的子模块
lithe-git src/lib.rs 9 895 → 222 src/ 下按主题的约 60 个模块(状态、提交、历史、变基、补丁、推送、搁置等),测试在 tests.rs、graph_tests.rs
lithe-debug src/engine.rs 7 333 → 457 engine/{state,messages,execution,breakpoints,inspection,step_filters,fields,tests}.rs
lithe-lsp-engine src/lib.rs 5 844 → 346 src/{engine,state,lifecycle,documents,requests,operations,events,server_messages,host_requests,function_calls,function_provider,plugin_server_calls,relay_hub,provider_events,configuration,scan_settings,validation,logging}.rs
lithe-core runtime/dispatcher.rs 4 120 → 731 runtime/dispatcher/ 下 14 个家族文件;CoreCommand 的这些家族改为嵌套子枚举(如 CoreCommand::Git(GitCommand::Status)),命令名字符串不变
lithe-plugin-manifest src/lib.rs 3 515 → 61 src/{manifest,validation,declarations,providers,provider_launch,launch,run_plans,commands,permissions,settings,settings_surfaces,templates,ui}.rs
lithe-build src/manifest.rs 2 571 → 219 manifest/{provider,detection,invocation,options,model,tasks,run,testing,diagnostics,dependencies,checks}.rs
lithe-lsp-client src/client.rs 2 564 → 284 client/{lifecycle,server_messages,json_rpc,validation,requests,diagnostics,results,capabilities}.rs
lithe-execution src/configuration.rs 2 471 → 89 configuration/{requests,document,generation,resolve,editing,launch,validation,merge,layers,requirements,inputs}.rs
lithe-plugin-rpc src/lib.rs 2 452 → 894 src/{functions,host_requests,host_notifications,host_params,failures}.rs;常量、错误码 codes 和测试留在 lib.rs
lithe-project src/files.rs 2 341 → 145 files/{events,requests,snapshot,visibility,search,search_everywhere,replace,text_io,paths,matcher}.rs
lithe-debug src/adapters.rs 2 175 → 215 adapters/{declaration,process,validate_adapter,validate_configuration,validate_launch,resources,start,plan,checks}.rs
lithe-toolchain src/resolution.rs 1 616 → 631 resolution/{probe,launch,discovery,snapshot,project,installations,automatic}.rs;resolve 留在父文件

跟着改的引用:

  • rust/fixtures/debug/v1-baseline.json 的 27 条测试证据路径从 engine.rs 改为 engine/tests.rs。
  • 插件函数协议拆成多个文件后,README、契约 README、协议更新记录和三个 SDK 的协议注释改为指向 rust/crates/plugin-rpc/src/ 目录。

契约和协议

插件契约有一处行为变化,已写进 shared/plugins/reference/protocol-changelog.md 的 2026-11-14 一行(本 PR #28):

  • schema 删除构建系统 model、test.results、dependencies 中不可达的 source: "hostIntegration" 分支,以及语言服务器 hostIntegration 的 capabilities/resources。
  • source: "hostIntegration" 现在按未知来源处理,报 plugin.manifest.invalid。原来带名字时报 plugin.integration.unsupported。这个来源从未被接受过,现有 fixture 不受影响。
  • 契约 README、指南和参考页已同步,并去掉了“社区插件”的说法。
  • 实现路径迁移:capabilities.rs → rust/crates/plugin-model/src/capabilities.rs,插件函数协议 → rust/crates/plugin-rpc/src/,函数中转 → rust/crates/plugin-function-relay/。

不动的部分

  • 命令名、C ABI、头文件位置、JSON 字段和其他错误码都不变。上面这处契约变化之外,没有改动算法和行为。
  • 测试随代码一起搬,没有删除测试。
  • 已合入 main 的 fix(lsp): allow cold managed runtimes to finish initialization #29:默认初始化超时 60000 毫秒和对应测试移到 lsp-engine/src/lib.rs、lsp-engine/src/tests.rs。
  • CI 工作流不变。注释门禁本来就遍历 rust/crates/*,新 crate 自动接受检查。
  • 桌面端合入后要做三件事:
    • 升级固定版本。
    • 更新 Lithe-IDEA 中指向 Core 旧路径的引用(如 AGENTS.md 里的 capabilities.rs、plugin_function.rs)。
    • 删除桌面端多余的 hostIntegration 检查。

验证

在 rust/ 下:

  • cargo fmt --all --check:通过。
  • cargo check --workspace --all-targets:本机目标和 x86_64-pc-windows-msvc 都没有警告。
  • cargo clippy --workspace --all-targets:本机目标和 x86_64-pc-windows-msvc 都是 0 条告警。
  • cargo test --workspace:1936 passed / 0 failed。

在仓库根:

  • scripts/rust-core/verify-rust-core-comments.sh:通过。
  • node shared/plugins/scripts/verify-docs.mjs:通过。
  • node shared/plugins/scripts/sdk-e2e.mjs:Node、Java、Rust 三个 SDK 和构建场景全部通过。

- 日志目录、通道、记录、查询、格式化、保留、收集计划、诊断包脱敏与清单、
  Core 事件队列移到 rust/crates/diagnostics,只依赖 lithe-protocol。
- 请求轨迹和辅助 crate 失败接线留在 core runtime;远程错误分类
  (failure_category、is_resource_already_gone)归 lithe-remote 的 ClientError。
- 测试钩子通过 test-support feature 只对 core 的 dev-dependencies 开放;
  diagnostics.* 分发测试移到 core/src/tests/diagnostics_dispatch.rs。
- 修正 capabilities 文档里指向私有项的链接和 logging README 的旧路径。
- lithe-text:UTF-16 位置与范围、文本编辑校验与规划、行索引,以及无语言服务器时的补全、悬停、导航和代码片段(原 lsp/lightweight 与 lsp 位置类型)
- lithe-editor:editor.* 命令的实现(原 core/src/editor),依赖 lithe-text
- editor.* 的分发测试移到 core/src/tests/editor_dispatch.rs
请求范围内的状态单独成 crate:来源 Source、请求追踪关联(trace),以及发往宿主的有序事件通道和脱敏(events,原 git::execution_events 的通用部分)。
Git 进程调用的 started/output/finished 事件仍在 git::execution_events,改用通道的 next_invocation、invocation_started、invocation_finished;remote、project、runtime 直接使用新 crate,不再经过 git。
execute_json_with_events 的回调测试移到 core/src/tests/request_events.rs。
FileNameKey、compare_file_names、compare_reference_names 移到
lithe_core_rules::file_names,git、lsp、project 直接引用;
workspace.orderEntries 命令和错误文本留在 core。纯比较的夹具测试
随之移到 lithe-core-rules。
core 的 remote 模块整体移到新 crate lithe-workspace:probe(SSH 探测)、
sessions(连接注册表)、host(宿主请求与进程/终端/监听资源)、upload、
fs(本地或远程文件系统),请求作用域的 Host/Scope 放在 crate 根。
remote 工作区命令白名单留在 core dispatcher,判定顺序和错误文本不变。
依赖 execute_json 的端到端测试移到 core/src/tests/remote_sessions.rs,
通过 test-support 特性注册进程内宿主会话。
core 的 git 模块整体移到新 crate lithe-git(约 2.9 万行),core 的
dispatcher 只负责路由 git.* 命令。Git 响应类型从 protocol/contracts.rs
移到 lithe_git::contracts,core 原样重新导出,JSON 形状、错误码不变。

- 只有 core 用到的入口和类型改为 pub 并补文档;只经 serde 读写的
  请求、响应字段收窄为 pub(crate),缩小跨 crate 的公开面。
- 依赖 execute_json 的共享 fixture 测试移到 core/src/tests/git_*.rs;
  其余测试留在 lithe-git,改为直接调用类型化入口,并在 crate 根加
  test_request/test_envelope 两个测试辅助,模拟 dispatcher 的解码与
  ok/data/error 包装。
- diff block fixture 入口和未跟踪目录阈值放在 test-support 特性下,
  供 core 的集成测试使用。
- branch-name 对照 fixture 移到 crates/git/tests/fixtures/。
- 顺手修 lithe-git 内可自动修复的 clippy 提示和两处指向私有项的文档链接,
  logging README 的 command_trace.rs 路径改到新位置。
把声明式插件清单各部分共用的基础定义抽成最底层的 crate
lithe-plugin-model(约 2600 行),为后续把 toolchain、vcs、debug、
build 等插件领域拆成独立 crate 打掉 plugins ↔ 领域的循环依赖。
JSON 形状、错误码不变。

- rejection:PluginRejection、Validation、invalid、invalid_template
  (原 template)、decode_payload、outcome;code()/field() 不再只在
  测试中可用,供 core 测试断言。
- names / version / template / icon:ID 与路径字母表、版本比较、
  `${...}` 模板解析、UIIcon。
- process:ServerProcess、LanguageServerLaunch、LaunchVariable 等
  服务进程声明与校验,连同原在 language_server_sessions 的解析超时
  常量和 validate_resolve_timeout。
- settings(含 documents、pages)与 executables 整体移入。
- 只有 core 用到的项改为 pub 并补文档,crate 内部用的保持 pub(crate)。
- marketplace 里与共用版本相同的 decode_payload 删除,改用共用版本;
  MAX_SETTINGS 移到 settings;KNOWN_RUNTIME_TOOLS 移到 build/manifest。
- 依赖 execute_json 的设置文档测试移到 core/src/tests/plugin_settings_documents.rs。
工具链策略(定义注册、查询回复、目录固定、固定来源、使用方偏好、解析与候选)
移到 rust/crates/toolchain,约 4.9k 行,只依赖 lithe-protocol 与
lithe-plugin-model。

- 清单校验仍属插件宿主:toolchain 定义 ManifestValidator,重建注册表的
  命令由 Core 注入 plugins::declarative::validated_manifest_json,
  toolchain 不再反向依赖 lithe-core。
- Core 以 `pub use lithe_toolchain as toolchain` 保留原路径,命令、JSON
  形状和错误码不变。
- 用 execute_json 的两个用例移到 core/src/tests;仅测试用的 path_within
  随用例移入测试文件。
- 测试总数不变:lithe-core 1380 + lithe-toolchain 10。
统一 VCS 模型(提供者声明、根目录检测、请求规划、回复校验)移到
rust/crates/vcs,约 2.2k 行,只依赖 lithe-protocol 与 lithe-plugin-model。

- vcs.detectRoots 需要重新校验整份清单:lithe-vcs 定义 VcsManifest
  trait,Core 为 DeclarativePluginManifest 实现,并在派发时注入
  validate_manifest_value;删去被 trait 取代的重复访问器。
- 补齐 Operation 各变体、PlannedRequest 与 DeclarationContext 字段的文档。
- Node SDK 注释里的 Core 路径改为 rust/crates/vcs/。
- 测试总数不变:lithe-core 1361 + lithe-vcs 19。
运行配置(三层文档合并、生成层、启动计划、参数文本、环境变量、上下文选择、
工作区扫描与运行发现)整体移到 rust/crates/execution,Core 用
`pub use lithe_execution as execution` 保留原路径,C ABI、JSON 形状和错误码不变。

- 依赖:lithe-diagnostics、lithe-plugin-model、lithe-protocol、lithe-toolchain、
  lithe-workspace;serde_yaml_ng 随 compose 检测器移入,Core 不再依赖它。
- 经调度器调用的 4 个测试移到 core/src/tests/execution_commands.rs;
  generated_layer::seed 只在 test-support 特性下公开,供 Core 测试预置生成层。
- 补齐公开字段文档,删去过时的“Crate-visible”注释。
- detectors/ 下的 cargo、compose、go、make、npm、procfile、python、shell
  检测器暂留,改由插件注入由 1lck/Lithe-IDEA#1856 跟进。

测试总数不变:lithe-core 1353 + lithe-execution 8 = 拆分前 1361。
DAP 调试引擎(会话、传输生命周期、断点重定位、变量/反汇编/内存分页、
projection v2、调试适配器声明校验与启动参数)整体移到 rust/crates/debug,
Core 用 `use lithe_debug as debug` 保留原路径,C ABI、JSON 形状和错误码不变。

- 依赖:base64、lithe-diagnostics、lithe-plugin-model、lithe-protocol、
  serde、serde_json、sha2,不依赖 Core。
- `debug.decodeBackendConfiguration` 原先直接调插件宿主的清单校验;现在由
  宿主通过 `DebugManifest` trait 和注入的校验函数提供,与 lithe-vcs 同一做法。
  DeclarativePluginManifest 实现该 trait,去掉了只剩这一个调用方的
  `debug_adapters()` 固有方法。
- 根模块不再整体 glob 导出 engine、types 等模块,只显式导出 Core 调度器
  用到的命令函数和请求类型;请求、声明类型的字段收窄为 crate 内可见,
  只放开 Core 实际读取的字段,并补齐这些公开项的文档。
- fixtures/debug/v1-baseline.json 里的源码路径改到 rust/crates/debug/src/。

测试总数不变:lithe-core 1248 + lithe-debug 105 = 拆分前 1353。
- project_generators 整体移到 rust/crates/project-generators(lithe-project-generators),
  只依赖 lithe-plugin-model 和 lithe-protocol。
- 新增 GeneratorManifest trait;project.generatorCatalog、generatorForm、generationPlan
  三个命令改为接收插件宿主注入的清单校验函数,Core 的 DeclarativePluginManifest
  实现该 trait,dispatcher 传入 validate_manifest_value。
- 能力表 capabilities.rs 移到 lithe-plugin-model(仍可经 lithe_core::plugins::capabilities
  访问),同步更新 README 与 shared/plugins/reference 两页里的源码路径。
- 工具 ID 校验原有两份实现(toolchain::definitions::tool_id 与 pins::valid_tool_id),
  合并为 lithe_plugin_model::{is_tool_id, is_tool_namespace, is_local_tool_id}。
- zip、rand 只被项目生成器使用,从 lithe-core 依赖中移出。

命令名、JSON 形状和错误码不变;单测总数不变(Core 1219 + 新 crate 29 = 原 1248)。
lithe-plugin-model 新增 PluginManifest trait(validate + id)。VcsManifest、DebugManifest、
GeneratorManifest 都以它为父 trait,命令改为泛型 cmd::<M>,不再逐个传入校验函数;
Core 的 DeclarativePluginManifest 实现 PluginManifest,dispatcher 与测试统一写
cmd::<Manifest>。为接下来拆 build(约 25 个读取清单的命令)准备同一种写法。

命令名、JSON 形状和错误码不变;测试数不变。
构建系统模型(声明校验、静态模型、argv 计划、输出解码)搬进独立 crate。
读插件清单的 26 条 build 命令改为泛型 BuildManifest,由 Core 的
DeclarativePluginManifest 实现;Core 删去不再使用的 chrono、quick-xml、
toml、ignore 依赖。
工作区文件与可见性、索引策略、搜索与搜索索引、本地历史、文档持久化决策和 Markdown 渲染搬进独立 crate,项目服务的响应模型(原 protocol/contracts.rs)随之搬入。语言服务会话在它之上:改动索引策略或搜索索引的三个入口改为接收 update_providers 回调,由 Core 传入 lsp::indexing_changed,调用顺序不变。目录访问计数通过 test-support feature 供 Core 测试读取。Core 删去 ammonia、comrak、encoding_rs,base64 与 sha2 只留在 dev-dependencies。
原生路径与 LSP 文档 URI 的互转(lsp.documentUri、请求路径解析、file: URI 解码与百分号解码)搬进 lithe-document-uri,语言服务运行时和策略命令都依赖它。文档身份、导航目标、工作区编辑计划、声明或用法、补全合并、激活策略和问题查询这七个纯决策命令连同只被它们使用的 WorkspaceScope 搬进 lithe-lsp-policy,原 lsp/host_policy 目录取消。两个 crate 互不依赖语言服务运行时,可与之并行编译。

七个命令的共享 fixture 测试走 execute_json,合并到 Core 的 tests/lsp_policy.rs;file URI 解码测试随函数搬进 lithe-document-uri。命令名、JSON 形状和错误码不变。
语言服务的进程边界(LspProcessSpec、进程句柄与启动器、本地子进程及 Windows 进程树)、远程工作区上的 stdio 转发、LSP Content-Length 分帧,以及引擎测试用的脚本化服务器,从 lsp/interface 搬进独立 crate。原 transport.rs 在新 crate 里改名为 framing.rs;脚本化服务器通过 test-support feature 供 Core 测试使用。Windows 专属测试重新启动自身测试二进制时使用的 libtest 名称随模块路径改为 process::tests::*,已用 x86_64-pc-windows-msvc 目标检查通过。分帧测试随函数搬入新 crate。
把各插件贡献的声明与校验从 lithe-core 的 plugins 模块拆成独立 crate,
只依赖 lithe-plugin-model 和 lithe-protocol,可与其它领域 crate 并行编译:

- lithe-plugin-editor:编辑器动作(actions)与编辑器提供者(providers)
- lithe-plugin-grammar:语法声明与语言配置
- lithe-plugin-native-ui:原生插件界面描述
- lithe-plugin-content-providers:内容提供者
- lithe-plugin-language-servers:语言服务器会话声明、启动答复与门控
- lithe-plugin-output-links:输出链接匹配与解析

PluginVersion 和已安装版本比较移入 lithe-plugin-model;经由
execute_json 的已安装版本 fixture 测试移入 core tests。命令、JSON
形状和错误码不变。
…-functions、lithe-plugin-keymap-import

- 插件函数协议(原 lsp/interface/plugin_function.rs)和宿主方法目录(原 plugins/host_api.rs)
  移入 lithe-plugin-rpc,打断 declarative 与 lsp::interface 之间的循环依赖。
- 插件后端声明(backend.rs)、插件导出函数(plugin_functions.rs)、快捷键导入(keymap_import.rs)
  各自独立成 crate。
- keymap-import 通过 KeymapImportManifest trait 读取清单里的提供者,不再依赖 declarative;
  经由 execute_json 和 declarative 的测试移到 core/src/tests/keymap_import.rs。
- offered_versions 移到 lithe-plugin-model::capabilities。
- 契约 README、协议更新记录、三个 SDK 的源码注释里的路径改为 rust/crates/plugin-rpc/src/lib.rs。

命令、JSON 形状、错误码均未改变。
- 声明式插件清单(原 plugins/declarative.rs 和 settings_surfaces.rs)移入
  lithe-plugin-manifest:清单校验、规范化,以及运行、测试、调试、设置、语言服务器计划。
- 该 crate 只依赖 build、vcs、debug、project-generators、toolchain 和各插件叶子 crate,
  不再经过 lithe-core。
- core 改用 lithe_plugin_manifest:: 路径;契约 README、能力与版本参考页、
  plugin-model 文档里的旧 lithe_core::plugins 路径一并更新。

命令、JSON 形状、错误码均未改变。
…删除 core 的 plugins 模块

- 插件网页(原 plugins/web_content.rs 及其测试)移入 lithe-plugin-web-content。
- 插件市场(原 plugins/marketplace.rs)移入 lithe-plugin-marketplace。
- core 的 plugins 模块只剩 capabilities 再导出,一并删除;调用方直接用
  lithe_plugin_model::capabilities。
- core 不再使用 regex,移除该依赖。

命令、JSON 形状、错误码均未改变。
- 删除只在测试里使用的 Swift 宿主模型适配器 lsp/languages/swift.rs;LSP 测试直接调用
  生产路径 client_feature_request_canonical,输入改用标准 LSP 形状(1lck/Lithe-IDEA#1858)。
- 删除无读者的 rust/fixtures/modules/built-in-v1.json 和 application-boundary.md 的
  Module Lifecycle Contract 一节(1lck/Lithe-IDEA#1858)。
- 删除没有任何代码构造的 protocol::CoreEvent 及其专用的再导出;4 处仍点名
  Swift、C++、TypeScript 客户端的注释改为描述当前宿主(1lck/Lithe-IDEA#1868)。
- 清空 rust/logging/events/agent.json 中 8 个没有发送方的事件,保留 agent 根,
  catalog_generated.rs 同步删除对应条目(1lck/Lithe-IDEA#1865)。

命令、JSON 形状、错误码均未改变。
- 语言服务器的 hostIntegration 解析为任意值后立即以 plugin.integration.unsupported
  拒绝(字段仍是 languageServers[i].hostIntegration.id);删除空名单、能力与资源
  模型、与执行提供者的重复声明检查、程序清单和启动计划里的输出
- 构建系统的 hostIntegration 同样存在即拒绝;删除 ModelSource、TestResultsSource、
  DependenciesSource 的 HostIntegration 成员及 outputs、plans、detect 的分支,
  以及只为它存在的官方插件检查和 DeclarationContext.official
- 契约 schema 删除三处 const "hostIntegration" 来源分支和语言服务器侧的
  capabilities、resources;README、指南与参考页同步,顺手去掉构建文档里的“社区插件”说法
- 现有 fixture 不变,错误码和字段路径不变

Refs 1lck/Lithe-IDEA#1857
…-server-policy,删除 core 的 lsp 模块

- lithe-lsp-client:纯状态的 LSP 客户端(协商、文档、功能请求、各提供者协议)
- lithe-lsp-engine:语言服务器会话、进程、超时、事件队列、插件服务器调用和跨插件函数中转
- lithe-plugin-function-relay:跨插件函数调用的准入规则和在途调用表
- lithe-plugin-server-policy:插件语言服务器的会话策略(准入、门、合并命令、操作归属)
- 文本、文档 URI 的测试随实现移到 lithe-text、lithe-document-uri;引擎日志命令的分发测试留在 core
- SUPPORTED_PLUGIN_API_VERSIONS 移到 plugin-model 的 capabilities
- client_feature_request_canonical 的布尔参数恒为 true,合并成 client_feature_request
- 只在 crate 内用的字段收回 pub(crate),其余公开项补全文档;契约 README 改指新路径
- clippy --fix 处理可机械修复的项
- 手工修复:冗余守卫、复杂类型改别名、strip_prefix、相同分支合并、stash 只剩 drop 的 match、
  diff_blocks 的 old/new 改名 old_lines/new_lines、as_infrastructure 改名 into_infrastructure、
  sort_by_key、clamp、slice::from_ref
- 8 个参数的三个函数沿用仓库已有的 too_many_arguments 放行写法
- project indexing 的 contains 在 Windows 下把小写化后的 String 再借成 &str,修复 clippy 改动后 String 不满足 Pattern
- workspace probe 测试的 json 宏不再只在 unix 下导入;四个依赖会话的测试只在 unix 下运行
- lsp-engine 只给 unix 测试用的 ScratchDirectory 与 open_document 加 cfg(unix)
- lsp-engine 的 runtime_error 把请求方法、文档、底层原因和进程退出码收进 FailureContext,
  19 处调用改用 FailureContext::request / default 加 with_underlying、with_exit_code
- 只被两处调用的 push_issue_log_event 内联,直接构造错误后交给 push_classified_log_event
- git 的 emit_output 改为 OutputTarget::emit:事件去向、操作 ID、调用 ID 和待定进度行
  收进 OutputTarget,Invocation 用 output_target() 取得
- 行为不变;build 里原有的两处放行保持不变
lib.rs 从 9895 行拆成 18 个主题模块和 tests.rs,根文件只留模块索引、
常量和测试辅助函数。条目正文不变,跨模块用到的私有条目放宽为 pub(crate)。
lib.rs 从 5844 行拆成 14 个主题模块,根文件只留公开入口函数。
impl RuntimeSession 按方法分组切成几个 impl 块放进对应模块;
条目正文不变,跨模块用到的私有条目和字段放宽为 pub(crate)。
engine.rs 从 7333 行拆成 engine/ 下 7 个主题模块和 tests.rs,
根文件只留会话生命周期的入口函数。条目正文不变,跨模块用到的
私有条目和字段放宽为 pub(crate);测试的 fixture 相对路径多一级。
CoreCommand 里 14 个大家族(git、lsp、debug、plugins、build、workspace、
diagnostics、toolchains、remote、runConfig、history、editor、ai、keymap)
改成嵌套子枚举,例如 CoreCommand::Git(GitCommand::Status)。命令名映射仍只在
CoreCommand::parse 一处,顺序不变;子枚举保留每个变体的原注释。

每个家族的分支搬到 runtime/dispatcher/<家族>.rs 的 dispatch 函数,分支体只把
CoreCommand::GitX 换成 GitCommand::X、parsed.payload 换成 payload;编译器仍检查
每个家族的分支穷尽。只有一个家族用的辅助函数随家族搬走(ai_response 到 ai,
CoreEventConfiguration 和 log_v2_result 到 diagnostics)。dispatcher.rs 从
4120 行降到约 760 行,只留请求入口、作用域设置和小家族的分支。

命令名、JSON 形状、错误码和 C ABI 都不变。
lib.rs 从 3515 行降到约 60 行,只留 crate 说明、依赖和模块索引。
新模块:manifest(清单模型与访问器)、providers(领域 crate 读取清单的
trait 实现)、templates、validation、ui、permissions、declarations、
run_plans、launch、provider_launch、commands、settings。

条目内容不变,只把跨模块用到的条目和字段放宽到 pub(crate),并在拆开的
impl 块前补上 impl 头。
按 rust/contracts/remote-workspace-protocol-v1.md 的语义为协议方法、事件、
消息、帧、客户端会话、传输链、端口转发、启动与安装引导的全部公开项补上
Rustdoc;代码不变。所有 crate 现在都按 -D missing_docs 检查,脚本和 README
不再保留豁免名单。

Closes 1lck/Lithe-IDEA#1863
engine.rs 拆分后测试搬到 engine/tests.rs,基线 fixture 里 27 处证据路径
还指着 engine.rs。按测试函数名重新定位,只改路径。
- lithe-build manifest.rs 2571 行 -> manifest/ 下 11 个模块,父文件 230 行
- lithe-execution configuration.rs 2471 行 -> configuration/ 下 11 个模块
- lithe-debug adapters.rs 2175 行 -> adapters/ 下 9 个模块
- lithe-project files.rs 2341 行 -> files/ 下 10 个模块,父文件 145 行
- lithe-lsp-client client.rs 2564 行 -> client/ 下 8 个模块,父文件 284 行
- lithe-plugin-rpc lib.rs 2452 行 -> 5 个模块,lib.rs 留协议常量和测试
- lithe-toolchain resolution.rs 1616 行 -> resolution/ 下 7 个模块

函数体不变;子模块里的 super:: 改成 crate::,跨模块用到的项改成
pub(crate),大 impl 块按方法切开放到对应主题。插件函数协议已不止一个
文件,README、契约、协议更新记录和三个 SDK 的注释改成指向
rust/crates/plugin-rpc/src/ 目录。
#29 修改的 rust/crates/core/src/lsp/interface/engine.rs 在本分支已搬进
lithe-lsp-engine。默认初始化超时 60000 毫秒改在 lsp-engine/src/lib.rs,
新测试 default_initialize_budget_survives_cold_start_and_still_expires
放进 lsp-engine/src/tests.rs,内容与 #29 一致。
@xiaoyumuxi

Copy link
Copy Markdown
Contributor Author

桌面端跟进 PR:1lck/Lithe-IDEA#1887(Draft)。它把 PINNED_CORE_REVISION 临时固定到本 PR 的 HEAD d235401,改了 302 处指向旧 Core 路径的文档和证据,删掉了桌面端 builds.go 里的 hostIntegration 判断。固定到 d235401 时,scripts/desktop/desktop-go.sh test ./... 的 53 个包全部通过。

本 PR 合入后,要先把 #1887 的 pin 改成 main 上的合并 commit,再合 #1887。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment