Skip to content

feat: add LSP folding ranges for comments - #551

Merged
magnus-madsen merged 1 commit into
masterfrom
folding-ranges
Jul 1, 2026
Merged

feat: add LSP folding ranges for comments#551
magnus-madsen merged 1 commit into
masterfrom
folding-ranges

Conversation

@magnus-madsen

@magnus-madsen magnus-madsen commented Jun 28, 2026

Copy link
Copy Markdown
Member

Adds support for the textDocument/foldingRange LSP request so multi-line comments can be collapsed (folded) in the editor — the extension side of flix/flix#12905.

Wiring

Follows the same request/response pattern as the existing features (e.g. formatting / document symbols):

  • server/src/handlers/lifecycle.ts — declares the foldingRangeProvider capability.
  • server/src/engine/jobs.ts — adds the lsp/foldingRange request (matches the string parsed by VSCodeLspServer on the compiler side).
  • server/src/handlers/symbols.ts — adds handleFoldingRanges. It is a URI-only request (no position/range), so it enqueues { uri } and resolves with the result array.
  • server/src/server.ts — registers connection.onFoldingRanges.
  • client/src/protocol/requests.ts — mirrors the request enum. The provider itself is auto-registered on the client by vscode-languageclient from the server capability, so no other client code is needed.

The wire format lines up exactly: the compiler returns { startLine, endLine, kind } with zero-indexed lines and kind comment, which vscode-languageclient maps straight to vscode.FoldingRange / FoldingRangeKind.Comment.

Test

Adds test/src/foldingRanges.test.ts and a foldingRanges test workspace whose Main.flix exercises all three foldable comment kinds (a /// doc-comment run, a // line-comment run, and a /* … */ block comment). The test asserts vscode.executeFoldingRangeProvider returns exactly those three ranges.

Wire up the `lsp/foldingRange` request so multi-line comments can be
collapsed (folded) in the editor, mirroring the Flix compiler side in
flix/flix#12905:

- declare the `foldingRangeProvider` capability
- add the `lsp/foldingRange` request and its URI-only handler
- register `connection.onFoldingRanges`

The provider is auto-registered on the client from the server
capability, so the client only mirrors the request enum.

Also adds an integration test covering doc-, line-, and block-comment
folding.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@magnus-madsen
magnus-madsen merged commit e495400 into master Jul 1, 2026
20 of 26 checks passed
@magnus-madsen
magnus-madsen deleted the folding-ranges branch July 1, 2026 12:21
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.

1 participant