Skip to content

fix(lsp): preserve generic closers before assignment - #1839

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
vicmcorrea:fix/lsp-generic-closer-assignment
Oct 23, 2026
Merged

Lorenzobattistela merged 2 commits into
bendlang:mainfrom
vicmcorrea:fix/lsp-generic-closer-assignment

Conversation

@vicmcorrea

Copy link
Copy Markdown
Contributor

Problem and fix

Formatting a generic closer adjacent to assignment can turn valid Bend into a parser error. This runs and prints Done{7}, but formatting inserts a space before >= and makes it a comparison inside the annotation:

import Base
def main()->Result<&2,&2,U32,U32>:
    x:Result<&2,&2,U32,U32>=Done{7}
    x

Keep > and = as separate tokens when glued to the preceding token or following a comma. Bend rejects a greater-than-headed infix glued to its left operand; a comma supplies no comparison operand. Reuse the existing angle spacing and tracking, while retaining spaced and leading-line >= comparisons.

Blast radius

Only tools/bend-fmt-lsp/src/formatter.ts and its existing test file change: one lexer predicate, one comment, and tests in the existing harness. No new tracking state, helper, parser, compiler, runtime, API, dependency or gate changes.

Invalid glued comparisons such as 2>=1 are no longer rewritten into valid spaced comparisons. Valid comparison behavior is preserved.

Regression evidence

Two new fixtures exercise an ordinary typed binding and a continued tuple body. Both run before formatting, fail parsing after main's formatting in all three styles, and retain Done{7} / (17, [3, 5]) with this fix. A third fixture preserves active formatting with a trailing generic comma; two assertions retain spaced and leading-line >=. The existing harness checks exact text, idempotence and actual CLI output.

Checks

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

Validation limits

Validated locally on macOS with Node v26.8.2 and Bun 1.3.11. No Linux, other runtime versions, editor-client UI or cluster gates were run; LSP validation uses stdio. The focused CLI controls do not establish correctness for every possible token layout.

@Lorenzobattistela
Lorenzobattistela merged commit b9a4b28 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