Skip to content

Add folding range lsp support#69

Open
ssmifi wants to merge 2 commits into
mainfrom
ssm/folding-range
Open

Add folding range lsp support#69
ssmifi wants to merge 2 commits into
mainfrom
ssm/folding-range

Conversation

@ssmifi
Copy link
Copy Markdown
Collaborator

@ssmifi ssmifi commented May 12, 2026

Closes #26
and implements the folding feature, which is basically a port from Langium.

Customization can be done via the FoldingRangeFilter interface.

@ssmifi ssmifi marked this pull request as ready for review May 12, 2026 12:00
Copy link
Copy Markdown
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I like the filter strategy approach! A few suggestion, see below 👍

Comment thread server/folding_range_provider.go
Comment thread server/folding_range_provider.go Outdated
Comment thread server/folding_range_provider_test.go Outdated
Comment thread test/fixture.go

func (f *Fixture) newDoc(doc *core.Document, ranges []RangeMarker, indices []IndexMarker) *Doc {
return &Doc{Document: doc, Ranges: ranges, Indices: indices, ctx: f.ctx, t: f.t}
return &Doc{Document: doc, Ranges: ranges, Indices: indices, ctx: f.ctx, t: f.t, fixture: f}
Copy link
Copy Markdown
Member

@msujew msujew May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Why pass the fixture if all you need is t anyway (which already exists in Doc)?

Comment thread test/doc_fixture.go Outdated

// AssertFoldingRanges verifies that the given folding ranges contain entries for all specified marker labels.
// Returns the Doc for chaining.
func (d *Doc) AssertFoldingRanges(result []lsp.FoldingRange, labels ...string) *Doc {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Instead of the test passing in the folding ranges, the method should retrieve them by itself. This keeps the tests much smaller. See as an example:

func (d *Doc) AssertDefinition(label string) {
d.fixture.t.Helper()
location, err := d.markerLocation(label, false)
if err != nil {
d.fixture.t.Fatalf("fbtest: %v", err)
}
defProvider, err := service.Get[server.DefinitionProvider](d.fixture.sc)
if err != nil {
d.fixture.t.Fatalf("fbtest: no definition provider available: %v", err)
}
links, err := defProvider.HandleDefinitionRequest(d.fixture.ctx, &lsp.DefinitionParams{
TextDocumentPositionParams: lsp.TextDocumentPositionParams{
TextDocument: lsp.TextDocumentIdentifier{URI: d.Document.URI.DocumentURI()},
Position: location.LspPosition(),
},
})
if err != nil {
d.fixture.t.Fatalf("fbtest: definition request failed: %v", err)
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then I can pass the fixture, yes? It's needed for the renameProvider anyways, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not required. But it's alright 👍

Comment thread internal/grammar/folding_range_provider_test.go
@ssmifi ssmifi force-pushed the ssm/folding-range branch from 129e25f to b65564c Compare May 20, 2026 12:06
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.

Folding feature

2 participants