Skip to content

fix(formatter): preserve inline lambda body alignment - #1583

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
vicmcorrea:fix/fmt-lambda-alignment
Oct 15, 2026
Merged

Lorenzobattistela merged 2 commits into
bendlang:mainfrom
vicmcorrea:fix/fmt-lambda-alignment

Conversation

@vicmcorrea

Copy link
Copy Markdown
Contributor

Problem and fix

Formatting an inline lambda can move its aligned continuation to ordinary indentation, turning a valid program into a parse error. For example, a lambda containing two array writes prints [7, 8] before formatting and fails afterwards.

Recognize the first body token after => and reuse the existing column pins to move its continuations together. This adds two executable lines and follows the column-shift approach requested in #1302.

Blast radius

Two bundled-tool files: tools/bend-fmt-lsp/src/formatter.ts and its existing formatter test. The shared formatBend path serves direct callers and LSP formatting requests. Existing header state and delimiter tracking are preserved. There is no exported API or source compatibility break.

The regression stays in the tool's own suite, following the external-tool gate guidance in #1389.

Regression evidence

Add one fixture to the existing pinned-layout cases, checking exact formatting, idempotence and equivalent execution through the real Bend CLI under default, four-space and tab options.

With the exact new test and the baseline formatter from b869cca, the normal package build succeeds and tests report 28 passed, 2 expected failures, 0 skipped. Both failures catch the lambda defect: the expected continuation column and actual CLI execution. The corrected formatter preserves [7, 8] and passes the same checks.

Checks

  • npm test in tools/bend-fmt-lsp: TypeScript build and Node formatter/server suites; 30 passed, 0 failed, 0 skipped.
  • Additional nested, parenthesized and annotated lambda checks: 18 baseline-failing cases pass with the fix; six control cases retain their results. Candidate formatting is idempotent.
  • Repository gate with CI-pinned ttok 0.3: 54/54.
  • git diff --check: passed.

Validation limits

Local checks used macOS arm64, Node 26.8.2 and Bun 1.3.11. The existing stdio LSP test covers ordinary formatting; the lambda regression exercises the shared formatter and real CLI, rather than an editor session. Windows, actual editor clients and mini-cluster gates were not run.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 15, 2026
@Lorenzobattistela
Lorenzobattistela merged commit 59c0c42 into bendlang:main Oct 15, 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