fix(reseed): force a bounded parse so an incomplete frontier still clamps stale folds - #297
Merged
Conversation
…te parse frontier
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.
What
Follow-up to #293.
reconcileReseedFoldsruns exactly once, synchronously, fromapplyDocumentright after an external reseed. When the post-reseed parse frontier was incomplete (!syntaxTreeAvailable(state, doc.length)— a large/just-opened doc reseeded with a real diff), it returned[]and never re-attempted, so #293's stale-fold clamp silently reverted for that fold's lifetime: an externally-inserted sibling heading could stay hidden behind a stale over-wide fold until the user unfolded.Fix
When the reseed changed the document and there are active folds, force one bounded complete parse at the call site before reconciling:
foldedRanges(view.state).size > 0gate — folding is opt-in, so the common no-fold reseed pays nothing (no forced parse).forceParsing(view, doc.length, RECONCILE_PARSE_BUDGET_MS = 500)— not a bareensureSyntaxTree:ensureSyntaxTreeadvances the parse context but leavessyntaxTree(state)(whichfoldable()reads) stale;forceParsingrepublishes the completed tree. This mirrors the existing seam already documented in the repo (forceParsing … force AND publish) and theoutline-panel.ts/list-transform.tsforced-parse precedents.Design decision (force vs. a reactive retry ViewPlugin) recorded in
.claude/docs/LEARNING.md. On a pathological multi-MB doc whose parse exceeds the budget,forceParsingreturnsfalseandreconcileReseedFolds's ownsyntaxTreeAvailableguard leaves the mapped fold untouched — the pre-existing accepted behaviour, recoverable by unfolding.Tests
test/webview/cm/fold/reconcile-reseed-folds.test.ts: on a genuinely-incomplete parse (large doc, no pre-forcing)reconcileReseedFoldsbails ([]); once the tree is complete it clamps the over-wide fold. Non-vacuity verified (flip → real FAIL).(r11)ineditor.test.ts: end-to-end throughapplyDocumenton a large doc — canonical fold range taken from a separate oracle state so the live parse stays incomplete; asserts the frontier is incomplete pre-reseed, then that the inserted sibling is revealed post-reseed. Red-first confirmed.flushPending()+editPosts()guards against any edit echo.Display-only, byte-identical round-trip. Full unit suite green (4147 tests);
pnpm compile+ lint clean.