Reader recovery: partial trees and every error (ADR 0009 phase 4) - #91
Merged
Conversation
Phase 4 of ADR 0009. readLocatedExprListRecovering re-windows broken input and re-runs the same strict parsers, remapping positions exactly (a window position on line 1 shifts by the base column; later lines already have real columns). Recovery is composition around the strict readers, not error-recovery alternatives woven through the grammar -- the strict path compile depends on is untouched. Semantics: one error per broken region, worded by the strict parser; parsing resumes at the next line that opens a form at column 1; and the final broken region is re-parsed with its unclosed brackets closed (respecting strings and comments), so the form being typed still yields a tree. Deliberately not done: mid-file broken regions are not bracket-completed, and error positions stay the strict reader's. The payoffs land where phase 3 said they would: the language server's last-good-parse defines cache is deleted, completion and semantic tokens run against the actual buffer mid-edit, ik check reports every broken region in a file, and the server publishes every error instead of the first. The ADR corrects "the largest single piece" in place: it landed smaller than the language server, because composing recovery from the strict parsers avoided the rewrite the estimate priced in.
Merged
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
Phase 4 of ADR 0009 — the last of the runtime-side phases.
Parser.readLocatedExprListRecoveringparses as much of a broken input as possible: every form that parses, plus one error per broken region, all with exact spans. The design keeps recovery outside the grammar — broken regions are re-windowed and re-run through the same strict parsers, with a small exact position-remap rule (a window position on line 1 shifts by the base column; every later line already has real columns) — so the strict readerscompiledepends on are untouched.Semantics:
[/(tracked as a stack), so the form being typed still yields a tree.Payoffs, exactly where phase 3 predicted
(define twice (vau …))␊)␊(twicestill classifies the trailingtwiceas an operative and publishes both errors.ik checkreports every broken region in a file (--jsonemits them all), instead of stopping at the first.The ADR also corrects its own estimate in place: "the largest single piece" landed smaller than the language server, because composing recovery from the strict parsers avoided the rewrite the estimate priced in.
Verification
--no-incrementalrebuild: zero warnings. Full suite: 446/446 (10 new: 8 recovering-reader tests — clean-input parity with the strict reader, resync, stray closers, per-region errors with exact line assertions, trailing completion, exact span remap, unclosed-string guard, nesting-bomb control — plus multi-regioncheckand a broken-buffer LSP test asserting the full semantic-token encoding and both diagnostics).ik check --jsonon a two-region file emits two diagnostics at lines 1 and 3, exit 1.faulted (process aborted): 0.checkand the language server; the strict parse path is byte-identical.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.