feat: add LSP folding ranges for comments - #551
Merged
Conversation
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>
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.
Adds support for the
textDocument/foldingRangeLSP 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 thefoldingRangeProvidercapability.server/src/engine/jobs.ts— adds thelsp/foldingRangerequest (matches the string parsed byVSCodeLspServeron the compiler side).server/src/handlers/symbols.ts— addshandleFoldingRanges. It is a URI-only request (no position/range), so it enqueues{ uri }and resolves with the result array.server/src/server.ts— registersconnection.onFoldingRanges.client/src/protocol/requests.ts— mirrors the request enum. The provider itself is auto-registered on the client byvscode-languageclientfrom 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 kindcomment, whichvscode-languageclientmaps straight tovscode.FoldingRange/FoldingRangeKind.Comment.Test
Adds
test/src/foldingRanges.test.tsand afoldingRangestest workspace whoseMain.flixexercises all three foldable comment kinds (a///doc-comment run, a//line-comment run, and a/* … */block comment). The test assertsvscode.executeFoldingRangeProviderreturns exactly those three ranges.