Repository navigation
fix(formatter): preserve separated brace arguments - #1505
Merged
Lorenzobattistela merged 1 commit intoOct 12, 2026
Merged
Conversation
Lorenzobattistela
approved these changes
Oct 12, 2026
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
Formatting a valid comma-optional call such as
choose(id {42 : U32})produceschoose(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
gapflag 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 directformatBendcalls 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
42with the fix. Five constructor/pattern, comma, and closing-brace/angle controls print42throughout.Checks
npm testintools/bend-fmt-lsp: TypeScript build and all 26 formatter/LSP tests pass, with no skips.bun gates/repo.tswith CI-pinnedttok0.3: 54/54 pass.git diff --checkpasses.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.