fix(windows): 单文件工作区 Diff 可展开省略的代码行 (#557) - #1009
Merged
Merged
Conversation
Single-file working-tree diffs were rendered from a sparse Git patch with Monaco folding disabled, so there was nothing to expand and the fold controls disappeared. - Request the whole file as context for single-file reviews and mark the result as full context; only those reviews enable folding. - Split full-context patches back into Git-equivalent 3-line hunks so hunk staging keeps its granularity. - Place hunk action bands by an explicit row anchor and per-side line count, keeping both sides aligned. - Re-attach the diff models when the text is replaced so the first real text after the empty mount folds instead of opening fully revealed. Co-Authored-By: Claude <noreply@anthropic.com>
The new full-context API tests queued their response with mockImplementationOnce, which assumed git_diff_file was the next invoke. Under CI's randomized order, repository discovery is sometimes not yet cached, so git_discover_repo consumed the queued response and the diff returned null (seed=1). Answer git_diff_file by command instead. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #557
问题
Windows 端「源代码管理 → 更改」中点开单个文件的 Diff 后,无法展开两个修改块之间省略的未改动代码。#910 修复了 Diff 自动关闭,但折叠/展开按钮也一起消失了(issue 最新评论:“之前有按钮现在按钮都没有了”)。
根因
monaco-git-diff.tsx传了collapse: false,Monaco 不生成折叠条,按钮因此消失。改动
请求完整文件内容(Windows 前端)
api/git-diff-api.ts:getWorkingTreePathDiff新增fullContext参数;新增getFullContextFileDiff(暂存区单文件),用独立的 read key,不写入现有getFileDiff缓存,避免行号栏、AI 等需要稀疏补丁的调用方拿到整份文件。两者请求contextLines: 2147483647(Git 接受的最大值),结果标记is_full_context: true。types/git.types.ts:GitDiff新增可选字段is_full_context。hooks/use-git-diff-actions.ts(有/无 Git 状态两条路径)、services/working-tree-diff-refresh.ts(默认 loader)、sidebar/utils/open-sidebar-resource.ts(侧边栏拖出的单文件 Diff)。按块暂存保持原粒度(Windows 前端)
utils/monaco-diff-rows.ts:完整上下文补丁只有一个@@ -1,N +1,N @@,直接拿来暂存会一次把整个文件写进索引。现在按 Git 默认 3 行上下文重新切出分块(相邻修改块的合并规则与 Git 一致),并生成正确的@@范围(包括空侧的-0,0写法)。完整文件的@@行不再显示;每块第一处修改标记actionAnchor,用来放「暂存/取消暂存」按钮。components/diff/monaco-git-diff.tsx:只有is_full_context的补丁才开启折叠,稀疏补丁维持collapse: false。共享渲染器(
frontend/editor/src/diff-review.ts)ReviewRow新增可选actionAnchor。按钮区(view zone)的位置改为按每一侧实际显示的行数计算:锚点行只在一侧存在时(例如纯新增行在左侧没有),左右两侧仍保持对齐。原有@@信息行的位置算法不变。setModel(null)→setModel(...)),让 Monaco 的未改动区域从头计算并默认折叠。文本相同的刷新(比如 Git 元数据变化)不重挂,读者已展开的区域会保留。验证与文档
.agents/notes/.../2026-09-15-macos-monaco-feasibility-probe.md:补充为什么只对单文件用完整上下文、分块如何切、为什么要重挂模型。shared/platform-feature-matrix.json:git-diff-review的验证动作补充“展开折叠且每块仍可单独暂存”,并重新生成docs/development/下两个视图。实现状态和验证状态不变。验证
bun test src/features/git src/features/sidebar:412 个全部通过。新增内容:monaco-diff-rows.test.ts:同一次修改的真实git diff --unified=2147483647和默认--unified=3输出逐块比对,确认切出的分块与 Git 一致;另有空侧@@范围、非完整上下文不变、非法分块 ID 拒绝等用例。git-status-api.test.ts:两个 API 发出的contextLines请求和is_full_context标记。cargo test(lithe-core):新增git_snapshot_diff_returns_the_whole_file_for_maximum_context,用真实 Git 仓库确认快照 Diff 接受最大上下文并返回单个完整分块。cargo test(src-tauri):新增preserves_full_file_context_for_single_file_review,platform::tests37 个全部通过。真实 WebKit 集成(
./scripts/probe-macos-monaco.sh --workbench-tests,CI 中已有):新增“首次完整文件 Diff 默认折叠、只有一个按钮、搜索可揭示折叠行”,68 个全部通过。去掉重挂模型后该用例会失败,已验证。浏览器内手动验证(Vite + 真实 Monaco,临时页面已删除):折叠条显示“88 hidden lines”;点击展开后原本隐藏的代码出现,Diff 不关闭;Stage 按钮回传派生分块 ID;并排与合并视图都能折叠,且各只有一个按钮区。
bun run typecheck、vp lint(改动文件)、verify-agent-notes、verify-test-stability、verify-platform-feature-matrix、verify-platform-feature-matrix-change origin/preview HEAD、verify-windows-boundaries、verify-shared-contracts、verify-rust-core-comments、verify-runtime-bundle-immutability全部通过。CI 修复(
aeb54b8d):git-status-api.test.ts新增的两个用例原先用mockImplementationOnce排队返回值,假设下一次 invoke 一定是git_diff_file。CI 以随机顺序(seed 1/3/7)运行时,仓库发现缓存有时还没建立,git_discover_repo先消费了排队的返回值,导致 seed=1 失败。改为按命令名返回响应;本地 17 个 seed 全部通过。未覆盖
🤖 Generated with Claude Code