Skip to content

fix(formatter): preserve separated brace arguments - #1505

Merged
Lorenzobattistela merged 1 commit into
bendlang:mainfrom
vicmcorrea:fix/formatter-brace-gaps
Oct 12, 2026
Merged

Lorenzobattistela merged 1 commit into
bendlang:mainfrom
vicmcorrea:fix/formatter-brace-gaps

Conversation

@vicmcorrea

Copy link
Copy Markdown
Contributor

Problem and fix

Formatting a valid comma-optional call such as choose(id {42 : U32}) produces choose(id{42 : U32}). Bend reads the glued name and brace as a constructor, so the formatted program no longer parses.

Reuse the token's existing gap flag to preserve one space between a name and a separated brace. Adjacent constructors stay glued. This also preserves separated equality and reflexivity arguments without adding parser logic or helpers.

Blast radius

Two files in tools/bend-fmt-lsp: the formatter's name-before-brace spacing rule and its unit tests. The rule serves direct formatBend calls and LSP document formatting; other separated name/brace forms, including constructor declarations, also retain one space. Spacing after closing braces and angle brackets keeps its existing behavior. No language, compiler, bundled bend-lint, gate, dependency, or changelog changes.

This addresses a different defect from #1302's column-sensitive layouts, although both PRs touch nearby formatter code.

Regression evidence

The new seven-case table covers ordinary/dotted names, equality and reflexivity arguments, explicit commas, nested constructors, and case-lambda braces, including idempotence. With the original spacing expression, the final suite has 25 passing tests and the new regression fails; with the fix, all 26 pass.

Real Bend CLI checks cover nine programs before and after formatting. Four annotation/equality/reflexivity/constructor-field cases fail after baseline formatting and print 42 with the fix. Five constructor/pattern, comma, and closing-brace/angle controls print 42 throughout.

Checks

  • npm test in tools/bend-fmt-lsp: TypeScript build and all 26 formatter/LSP tests pass, with no skips.
  • bun gates/repo.ts with CI-pinned ttok 0.3: 54/54 pass.
  • Real Bend CLI comparisons and formatter idempotence pass; git diff --check passes.

Validation limits

Local checks ran on macOS arm64 with Node 26.8.2 and Bun 1.3.11. Windows, the minimum supported Node 22, and the cluster test/performance/safety/ping gates were not run. These focused checks do not establish semantic preservation for every formatter input. #1302 may require a context rebase if it lands first; its complete suite was not rerun here.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 12, 2026
@Lorenzobattistela
Lorenzobattistela merged commit 500d495 into bendlang:main Oct 12, 2026
1 check passed
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