Repository navigation
fix(lsp): preserve match scopes across forall bodies - #1791
Merged
Lorenzobattistela merged 1 commit intoOct 20, 2026
Merged
Conversation
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.
Problem and fix
A column-zero
@in a match-arm's forall type clears the formatter's remembered match scope. A latercaseis then dedented outside the match, turning valid Bend into a parse error; the shared layout fingerprint accepts that output.Reset scopes on actual
def,type, andlawtokens in the existing delimiter-depth-zero scan. This also preserves declaration boundaries when@unsafeis split across lines or the declaration keyword is indented.Blast radius
Two files in
tools/bend-fmt-lsp: one scope-reset condition insrc/formatter.tsand fixtures in its existing CLI-backed test. This affects match indentation during document formatting and its layout fingerprint. No public API or language compatibility break; the compiler, parser, and repository gates are unchanged.Regression evidence
Four added fixtures cover a column-zero forall body, a grouped forall with an
unsafebinder, and split/indented decorated declarations with and without comments. Each source runs before formatting; all three indentation styles must change the text, preserve the expected output (7or20), and be idempotent.The updated test fails against main with a misindented
caseparse error. It also fails if the fix merely removes@from the old reset condition, catching the lost decorated-declaration boundary.Checks
npm test: build and all 33 tests pass, zero skips, including the LSP stdio session.npm pack --dry-run: build passes; 14-file package inventory.bun gates/repo.tswith CI-pinnedttok0.3: 54/54.git diff --check: passes.Validation limits
Local checks ran on macOS arm64 with Node 26.8.2 and Bun 1.3.11. No Linux run or interactive editor-client check. The CLI regressions use Bend's source interpreter; compiled CPU/GPU lanes and the cluster/performance gates were not run for this formatter-only change.