Skip to content

fix(lsp): preserve body alignment after tuple commas - #1833

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
vicmcorrea:fix/lsp-comma-body-alignment
Oct 23, 2026
Merged

Lorenzobattistela merged 2 commits into
bendlang:mainfrom
vicmcorrea:fix/lsp-comma-body-alignment

Conversation

@vicmcorrea

Copy link
Copy Markdown
Contributor

Problem and fix

Formatting a continued tuple body after a comma can turn valid Bend into a parser error. For example, this runs and prints (17, [3, 5]), but formatting moves the second array write out of the first write's column:

import Base
def main() -> U32 & Array<U32>:
  a = [0 : U32 * 2n]
  (17,a[0]<-3
      a[1]<-5)

Start the existing bounded body scope after commas at parenthesis depth, outside generic arguments. Continuation lines then move with their body anchor, as they already do after (. This extends #1816 using #1803's existing scope expiry.

Blast radius

Only tools/bend-fmt-lsp/src/formatter.ts and its existing test file change. Parenthesis tracking limits the new origins to parenthesized comma sites, including call/declaration parentheses; commas inside generic arguments or unparenthesized array/constructor contexts are excluded. No parser, compiler, runtime, API, dependency or gate changes.

Regression evidence

Two fixtures extend the existing exact-output/idempotence and real-CLI harnesses: a continued tuple item and a tuple followed by an observably consumed call argument. The original programs print (17, [3, 5]) and [28, 5]; formatted versions fail parsing on main in default, four-space and tab modes, and retain those outputs with the fix.

Checks

  • npm test: 33/33, zero skips, including CLI regressions and the LSP stdio session.
  • npm pack --dry-run --json: build succeeds; 14 expected package files.
  • bun gates/repo.ts: 54/54 with CI-pinned ttok 0.3.
  • git diff --check: passes.

Validation limits

Run locally on macOS with Node v26.8.2 and Bun 1.3.11. No Linux, other Node versions or editor-client UI validation; the LSP was tested over stdio. Cluster gates were not run. The token-based formatter's existing generic-close/assignment tokenization and unchanged-source fallback limitations remain outside this fix.

@Lorenzobattistela
Lorenzobattistela merged commit 5150fe2 into bendlang:main Oct 23, 2026
1 check passed
@Lorenzobattistela Lorenzobattistela mentioned this pull request Oct 23, 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