fix(ui): preserve syntax state across folded hunks - #669
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR preserves lexical state for partial source-backed diffs by validating full-source prefixes, highlighting them through Pierre, and remapping tokens onto the visible patch rows.
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking watch-mode cache-efficiency issue for unchanged partial files. Source-prefix validation and token remapping have guarded fallbacks and focused regression coverage, but cache invalidation follows newly allocated fetcher objects rather than stable source revisions, forcing unnecessary source loading and highlighting after reloads. Files Needing Attention: src/ui/diff/useHighlightedDiff.ts Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Partial diff metadata] --> B{Source fetcher available?}
B -- No --> F[Highlight patch fragment]
B -- Yes --> C[Fetch old and new source]
C --> D{Visible lines and gaps validate?}
D -- No --> F
D -- Yes --> E[Highlight validated source prefixes]
E --> G[Remap tokens to partial line indexes]
F --> H[Build split or stack rows]
G --> H
Prompt To Fix All With AI### Issue 1
src/ui/diff/useHighlightedDiff.ts:89-94
**Fetcher identity defeats cache reuse**
Each session reload rebuilds `DiffFile` and its source fetcher, so assigning cache IDs by fetcher object identity gives an unchanged partial file a new highlight key. This discards reusable highlights and prefetched work, forcing another source fetch and highlight pass and causing an avoidable plain-text-to-highlighted repaint in watch mode.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "fix(ui): preserve syntax state across fo..." | Re-trigger Greptile |
| let id = sourceFetcherIds.get(file.sourceFetcher); | ||
| if (id === undefined) { | ||
| id = nextSourceFetcherId; | ||
| nextSourceFetcherId += 1; | ||
| sourceFetcherIds.set(file.sourceFetcher, id); | ||
| } |
There was a problem hiding this comment.
Fetcher identity defeats cache reuse
Each session reload rebuilds DiffFile and its source fetcher, so assigning cache IDs by fetcher object identity gives an unchanged partial file a new highlight key. This discards reusable highlights and prefetched work, forcing another source fetch and highlight pass and causing an avoidable plain-text-to-highlighted repaint in watch mode.
Knowledge Base Used: Diff Rendering Pipeline
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ui/diff/useHighlightedDiff.ts
Line: 89-94
Comment:
**Fetcher identity defeats cache reuse**
Each session reload rebuilds `DiffFile` and its source fetcher, so assigning cache IDs by fetcher object identity gives an unchanged partial file a new highlight key. This discards reusable highlights and prefetched work, forcing another source fetch and highlight pass and causing an avoidable plain-text-to-highlighted repaint in watch mode.
**Knowledge Base Used:** [Diff Rendering Pipeline](https://app.greptile.com/modem/-/custom-context/knowledge-base/modem-dev/hunk/-/docs/ui-diff-rendering.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed in 42c76fe. Source readers can now expose a stable sourceCacheKey, which is combined with the per-file patch fingerprint. The Git adapter derives it from resolved refs and semantic index entries, so equivalent reload-created fetchers reuse highlighted output while changed source bases still invalidate safely. Added cache, adapter-boundary, and Git regression coverage plus extension documentation.
Responded by Pi using OpenAI GPT-5.6.
This comment was generated by Pi using OpenAI GPT-5.6
b84b7e1 to
42c76fe
Compare
0c7bdc0 to
473cfc4
Compare
d6043a2 to
959ab4d
Compare
Summary
Screenshots
Before
Patch-only highlighting incorrectly keeps
def hello doin the hidden heredoc's string state.After
Source-backed highlighting restores
defto the Elixir keyword state.Testing
bun run typecheckbun run lintbun run format:checkbun run test:integration: 87 passedbun run test:tty-smoke: 9 passedNotes
This corrects source-backed reviews such as
diff,show, andstash show. Arbitrary source-lesshunk patchinput remains best-effort because omitted lexical context cannot be reconstructed reliably.bun run testhas one unrelated existing failure insrc/extensions/hostRuntimeModules.test.ts, reproduced on untouchedorigin/main.Addresses #664.
This PR description was generated by Pi using OpenAI GPT-5.6