Skip to content

fix(lsp): preserve match scopes across forall bodies - #1791

Merged
Lorenzobattistela merged 1 commit into
bendlang:mainfrom
vicmcorrea:fix/lsp-declaration-boundaries
Oct 20, 2026
Merged

Lorenzobattistela merged 1 commit into
bendlang:mainfrom
vicmcorrea:fix/lsp-declaration-boundaries

Conversation

@vicmcorrea

Copy link
Copy Markdown
Contributor

Problem and fix

A column-zero @ in a match-arm's forall type clears the formatter's remembered match scope. A later case is 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, and law tokens in the existing delimiter-depth-zero scan. This also preserves declaration boundaries when @unsafe is split across lines or the declaration keyword is indented.

Blast radius

Two files in tools/bend-fmt-lsp: one scope-reset condition in src/formatter.ts and 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 unsafe binder, 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 (7 or 20), and be idempotent.

The updated test fails against main with a misindented case parse 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.ts with CI-pinned ttok 0.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.

@Lorenzobattistela
Lorenzobattistela merged commit d0fc76f into bendlang:main Oct 20, 2026
1 check passed
@Lorenzobattistela Lorenzobattistela mentioned this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants