Skip to content

feat(git): Git 控制台按类别记录内部查询并支持显示选项,默认与 IntelliJ IDEA 一致 - #64

Merged
xiaoyumuxi merged 4 commits into
mainfrom
feat/console-filters
Nov 16, 2026
Merged

xiaoyumuxi merged 4 commits into
mainfrom
feat/console-filters

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

关联 Issue / Linked issue

#2025 要求在 Version Control 设置里提供开关,按类别省略 Git 控制台里的内部查询,并调整显示方式;所有开关的初始状态和 IntelliJ IDEA 的控制台一致。本 PR 是 Core 部分:按类别决定记不记录查询,git.consolePresentation 接受显示选项。桌面端的设置页和控制台在 1lck/Lithe-IDEA#2029 里,它把 PINNED_CORE_REVISION 升到本分支后关闭 #2025。

PR 类型 / Type

  • feat:新功能或用户可见的改进

改动说明 / What changes

背景 / Why

原来只有一个布尔开关 gitExecution.reportQueries:打开后,除 background 来源以外的所有内部只读查询都进入控制台。用户只能全开或全关,打开时 diff、日志浏览、注解、面板列表这些高频读取会挤满控制台,还会占掉控制台的 200 条记录。

IDEA 的控制台不显示任何只读查询(silent handler),只显示用户执行的命令。本 PR 把开关拆成 9 个查询类别,默认一个都不记录,与 IDEA 一致;控制台不记录的类别根本不产生执行事件,所以不占记录容量。另外加了 4 个显示选项,默认值同样是 IDEA 的显示方式。

改动 / Changes

查询类别(rust/crates/git/src/console/types.rs、新文件 console/category.rs)

  • 新枚举 QueryCategory(camelCase 序列化),共 9 类:
    类别 含义
    references 没有用户操作、仓库变化后读取分支和引用
    reload 用户执行操作之后重新加载视图
    diffRefresh 保存文件后重新读取打开的 diff
    diff 用户打开的文件、提交、比较和 stash diff
    log 日志里的历史、引用和提交详情
    logPathFilter 日志按路径过滤时逐个提交读取的文件列表
    annotate 注解和行历史
    panels worktree、stash、remote、PR 和设置等列表与面板
    checks 预览、预检、计划和操作本身的查询
  • category::of_command(command) 按请求命令推出类别:
    • diff:git.diff、git.comparison、git.planDiffBlocks;
    • log:git.history*、git.references、git.referenceTree、git.graphProjection、git.tags、git.commit、git.commitFiles、git.changedFileGroups;
    • annotate:git.blame、git.lineHistory;
    • panels:git.worktrees、git.stashes、git.remotes、git.remoteUrl、git.pullRequestContext、git.untrackedDirectory、git.repositorySetup、git.executionInspect;
    • 其他所有 git.* 都算 checks;
    • Git 以外的命令没有类别(None),它们的查询不会被记录。

执行选项(execution_policy.rs、runtime/dispatcher.rs)

  • GitExecutionOptions:
    • 删除 report_queries(reportQueries)。结构体是 deny_unknown_fields,旧桌面端继续发 reportQueries 会直接报错,所以桌面端必须和本 PR 一起升级。
    • 新增 console_queries: Vec<QueryCategory>(consoleQueries):控制台记录哪些类别,默认空,即 IDEA 的行为。
    • 新增 query_category: Option<QueryCategory>(queryCategory):命令本身分不出类别时由宿主指定,例如操作后的 reload、保存后的 diff 刷新、后台的引用读取。
    • 新增 command_category:#[serde(skip)],不从请求读取,由调度器调用 for_command(&parsed.command) 填入。
  • execution_policy::reports_queries():先取宿主指定的 queryCategory;没有时,非 background 来源取命令的类别;再看 consoleQueries 是否包含它。background 请求只有宿主指定了类别才会被记录,自动刷新和 watcher 仍然不进控制台。
  • execution_events::Invocation::reported 改用 reports_queries();started 事件里的 query: true 语义不变。

显示选项(console/types.rs、console/mod.rs、command.rs、output.rs)

  • git.consolePresentation 请求新增 display(Display,deny_unknown_fields),4 个字段默认都是 false,即 IDEA 的显示方式:
    字段 为 true 时
    foldShortQueries 成功查询的输出在 10 行以内时也折叠,只显示命令行
    showCompletedWithoutOutput 显示 completedWithoutOutput 提示;默认不显示,IDEA 在没有输出的命令后不打印任何内容。waitingForOutput、fetchUnchanged 不受影响
    hideTemporaryConfig 命令片段里完全不出现 Core 的临时 -c 配置,而不是折叠;操作自己参数里的 -c 照旧原位折叠
    hideRepository repositoryLabel 为空,搜索也不再匹配仓库路径
  • 显示选项只影响呈现结果,不改动保存的记录,也不影响复制出来的原始命令。
  • 行为变化:没有 display 时 completedWithoutOutput 不再出现(以前总会出现)。原来依赖它的夹具用例改为显式传 showCompletedWithoutOutput: true。

折叠规则(console/output.rs、console/command.rs、新文件 console/deletion.rs)

  • 输出超过 10 行才折叠:连续的 Git 进度行超过 10 行才合成一个 progress 片段,成功查询的输出超过 10 行才合成一个 query 片段;10 行以内照常显示。foldShortQueries 让成功查询的短输出也折叠。失败的记录什么都不折叠。
  • 删除类命令什么都不折叠:它的临时 -c 配置、进度和查询输出都完整显示,与显示选项无关,让用户看清删掉了什么。hideTemporaryConfig 对删除类命令仍然生效,因为那是用户明确选的省略,不是折叠。
  • 删除类命令(只看 -- 之前的选项):rm、clean(含试运行 clean -n);带 -d/-D/--delete 的 branch、tag、update-ref、symbolic-ref;带 -d/--delete/--prune 或空源 refspec(:refs/heads/topic)的 push;带 -p/--prune/-P/--prune-tags 的 fetch、pull;remote remove/rm/prune 和 remote update --prune;带 --unset、--unset-all、--remove-section、unset、remove-section 的 config;stash drop/clear/pop;worktree remove/prune。reset、checkout -- 这类回退不算删除。 夹具 console-presentation-v1.json 的 deletions 表逐条固定这份清单。

失败的未记录查询仍然报告(execution_events.rs、execution_policy.rs)

  • 没开类别的查询在非 background 请求里失败(出错,或者退出码不是查询本身的回答)时,Core 在它结束时一次发出 started(query: true)、stderr 行和 finished,控制台能看到失败的命令、诊断和退出码;不保留 stdout,请求也不再需要 failureRecord。取消的查询不报,background 请求里的未记录查询失败了也不报。

started 事件带类别(execution_events.rs、execution_policy.rs)

  • 已报告查询的 started 事件带 queryCategory,宿主停止记录某个类别时可以移除它已保存的该类成功查询;可见命令和没有类别的查询不带。
  • execution_policy::query_category() 给出当前请求的查询类别,reports_queries() 拿它对照 consoleQueries。

契约与夹具

  • rust/contracts/rust-core-api.md:
    • gitExecution 的字段从 reportQueries 改为 consoleQueries 和 queryCategory;
    • 写明 9 个类别、命令到类别的映射、background 规则,以及未记录的类别不产生事件、不占控制台容量;
    • 写明 git.consolePresentation 的 display 字段和默认值。
  • 新夹具 rust/fixtures/git/console-queries-v1.json:queryCategories 列出全部 9 个类别(宿主读取它核对自己的类别名,gitExecution 拒绝其他名字),命令到类别的映射,以及 8 个“是否记录”的用例(IDEA 默认、记录的类别、其他类别、未列出的命令算 checks、后台刷新、指定类别覆盖命令类别、后台指定类别、Git 以外的命令)。
  • rust/fixtures/git/console-presentation-v1.json 新增用例:默认不显示无输出提示、10 行以内的查询输出和进度默认可见、超过 10 行才折叠、foldShortQueries 折叠短输出、隐藏临时配置但保留操作自己的配置、隐藏仓库后标签为空且不参与搜索;新增 deletions 表,逐条验证删除类命令的配置、进度和输出都不折叠,以及 reset、checkout -- 不算删除。
  • 契约还写明了 10 行阈值、删除类清单、失败的未记录查询如何报告,以及 started 事件的 queryCategory。

测试

  • execution_policy::tests::console_queries_follow_the_named_or_command_category:逐条校验夹具里的映射和用例,作用域结束后恢复为不记录;queryCategories 用穷尽 match 对照枚举,新增类别而清单没跟上时编译失败。
  • execution_events 的 reported_queries_are_marked_apart_from_visible_commands 改为用 consoleQueries: ["log"] 和 git.history,并校验查询的 started 带 queryCategory: "log"、可见命令不带;新增 unrecorded_queries_report_only_a_real_failure:失败的未记录查询一次报出 started、stderr、finished,取消的查询和后台请求不报。
  • core/src/tests/git_workspace_commit.rs 的 git_internal_queries_report_events_only_when_the_request_asks:真实仓库上验证未记录的类别、其他类别、后台刷新都不产生事件,记录的类别每条 started 都有对应的 finished。
  • 呈现测试读取上面的夹具。

不在本 PR 范围内 / Out of scope


类型专属:feat

多平台对齐

  • 两端都具备:逻辑都在 Core,macOS 和 Windows 共用;桌面端是同一份 Viva 代码。

范围检查 / Scope checks

  • 功能矩阵:Core PR 不改矩阵。Git 控制台在 Lithe-IDEA 的 git-history 条目,由桌面端 PR 更新。
  • 插件归属:N/A,只涉及 Git 宿主功能,没有按插件分支。
  • UI 验证 / i18n:N/A,没有界面文案;开关的文案在桌面端 shared/i18n/。
  • 统一日志系统:N/A,没有新增日志事件;generate-log-events.mjs --check 通过。
  • 逻辑归属:类别映射、是否记录、呈现规则都在 Rust Core,宿主只传偏好和它知道的读取类别。
  • 性能与内存:没有新增线程、进程、轮询或定时器。reports_queries() 只在启动查询时做一次最多 9 项的线性查找。默认不记录查询,控制台的事件比以前更少。
  • 设置:Core 不读写设置文件;偏好由桌面端保存在 Lithe 自己的设置里(这是 Lithe 自己的偏好,不对应 Git 的配置文件)。
  • 插件契约:N/A,改的是宿主与 Core 之间的 rust-core-api,没有改 shared/plugins/ 的插件契约、能力版本或插件函数协议。
  • 发行包与资源:N/A,不写任何文件。
  • 无用代码:reportQueries 及其判断已删除,没有留下兼容分支。

验证 / Verification

本机为 Apple M4、macOS arm64,在 5aae479 上运行。

命令或操作 平台 结果
cargo fmt --manifest-path rust/Cargo.toml --all -- --check macOS arm64 通过
scripts/rust-core/verify-rust-core-comments.sh git、… core macOS arm64 通过
node scripts/rust-core/verify-platform-tests.mjs macOS arm64 通过
node scripts/logging/generate-log-events.mjs --check macOS arm64 通过
node shared/plugins/scripts/verify-docs.mjs macOS arm64 通过
cargo clippy --locked … -p lithe-git -p lithe-core --all-targets -- -D warnings macOS arm64 通过
同上加 --target x86_64-pc-windows-msvc macOS 交叉检查 Windows 目标 通过
cargo test --locked … -p lithe-git -p lithe-core macOS arm64 990 个通过,0 个失败
桌面端(1lck/Lithe-IDEA)固定到 5aae479 后的 desktop-go.sh test ./internal/core ./internal/settingswindow ./internal/workbench macOS arm64 通过,见 1lck/Lithe-IDEA#2029

未能执行的检查和原因:

  • 没有在 Windows 上实机运行;Windows 目标只做了 clippy 交叉检查,CI 会跑 Windows 测试。
  • 完整工作区的 cargo test 在本机沙盒里会因 lithe-remote 的测试失败(与本 PR 无关),所以只跑了改动涉及的 lithe-git、lithe-core;完整工作区由 CI 覆盖。

提交前确认 / Final checks

  • 分支从 main 创建,并已用 merge 合入最新 main(ad148ec),目标分支 main
  • 以 Draft 提交
  • 没有无关改动,没有提交产物、凭据或个人路径
  • Core 侧验证没有启动 Lithe 应用

…details it shows

- gitExecution.consoleQueries lists the query categories a console records
  (references, reload, diffRefresh, diff, log, logPathFilter, annotate, panels,
  checks); gitExecution.queryCategory names the category of a read the command
  alone does not tell apart. reportQueries is removed. An empty list records no
  internal query, as IntelliJ IDEA does, and an unrecorded query emits no events,
  so it takes none of the console's capacity.
- console::category::of_command maps every request command to its category;
  a background request without a named category stays silent.
- git.consolePresentation accepts display { foldSingleLineQueries,
  showCompletedWithoutOutput, hideTemporaryConfig, hideRepository }. All default
  to false, which is IDEA's console: single-line query output stays visible, a
  command without output shows no notice, temporary -c values fold, and the
  repository label shows.
- Fixtures: console-queries-v1.json (new) and console-presentation-v1.json
  cases for each display option; rust-core-api.md documents both.
…tion, report failed queries

- Progress blocks and query output fold only when they are longer than ten lines;
  `display.foldSingleLineQueries` becomes `display.foldShortQueries`, which folds a
  successful query's output at any length.
- A record whose arguments delete something (rm, clean, branch/tag/update-ref/symbolic-ref
  -d, push --delete/--prune/:ref, fetch/pull --prune, remote remove/prune, config --unset,
  stash drop/clear/pop, worktree remove/prune) folds neither its `-c` configuration, its
  progress, nor a query's output. The shared `deletions` table fixes the list.
- A query the console does not record still reports itself once it fails in a request
  that is not `background`, as every query did before categories: started, stderr and
  finished arrive together; stdout is not kept, and a cancelled query stays silent.
- A reported query's `started` event carries `queryCategory`, so a console that stops
  recording a category can drop the successful queries of it that it kept. A visible
  command, and a query of no category (an automatic refresh or watcher), carries none.
- `execution_policy::query_category()` gives the running request's category, and
  `reports_queries()` checks it against `consoleQueries`.
- `console-queries-v1.json` lists every category in `queryCategories`, which hosts read
  to check their own names; a test matches the list against the enum, so it fails to
  compile when a category is added and the list is not.
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 16, 2026 09:25
@xiaoyumuxi
xiaoyumuxi merged commit 957a349 into main Nov 16, 2026
6 of 7 checks passed
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