-
Notifications
You must be signed in to change notification settings - Fork 749
Folding Ranges implementation #1326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Folding Ranges implementation #1326
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request implements folding ranges support for the LSP by combining tests from tsserver and LSP, adding several utility functions and test cases to handle folding functionality in the compiler codebase. Key changes include:
- Introducing new folding range support in the language service (internal/ls/folding.go) and integrating it via the LSP server (internal/lsp/server.go).
- Adding a new helper function (GetLineEndOfPosition) in the scanner and refactoring certain utility functions in the printer.
- Expanding the test coverage for outlining and folding with extensive tests in internal/ls/folding_test.go.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/scanner/scanner.go | Added GetLineEndOfPosition to compute the end position of a line. |
| internal/printer/utilities.go | Updated and renamed helper functions to use consistent naming conventions. |
| internal/lsp/server.go | Added folding range handling in LSP server. |
| internal/ls/utilities.go | Adjusted LSP range creation using astnav.GetStartOfNode. |
| internal/ls/folding_test.go | Introduced comprehensive tests for folding range functionality. |
| internal/ls/folding.go | Implemented folding range creation and management functions. |
| internal/ast/utilities.go | Added helper isDeclarationKind to classify declaration nodes. |
Comments suppressed due to low confidence (1)
internal/scanner/scanner.go:2300
- [nitpick] The naming of GetLineEndOfPosition is very similar to GetEndLinePosition, which could be confusing. Consider standardizing the naming to more clearly distinguish their roles (e.g., by using a consistent verb pattern).
func GetLineEndOfPosition(sourceFile ast.SourceFileLike, pos int) int {
| } | ||
|
|
||
| func (l *LanguageService) addRegionOutliningSpans(sourceFile *ast.SourceFile) []*lsproto.FoldingRange { | ||
| regions := make([]*lsproto.FoldingRange, 0, 40) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, where does the 40 initial capacity come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
40 is the max depth that strada used, but I don't think that we actually need to prealloc these lists.
|
|
||
| func addOutliningForLeadingCommentsForPos(pos int, sourceFile *ast.SourceFile, l *LanguageService) []*lsproto.FoldingRange { | ||
| p := &printer.EmitContext{} | ||
| foldingRange := make([]*lsproto.FoldingRange, 0, 40) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect to typically see around 40 ranges for a comment position?
| return out | ||
| } | ||
|
|
||
| func visitNode(ctx context.Context, n *ast.Node, depthRemaining int, sourceFile *ast.SourceFile, l *LanguageService) []*lsproto.FoldingRange { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think thins might turn out better if all of this code were instead methods in on a struct, like foldingRangeCollector, then you don't need to pass everything down so much, the deth can just be there, you can append into a slice there, etc
jakebailey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I resolved all of the outdated comments.
Most everything else are just refactors or nits. I think this is pretty much ready? The only one I think we should actually fix is the comparison function, then everything else can be done later depending on who has time/bandwidth.
internal/fourslash/tests/gen/correuptedTryExpressionsDontCrashGettingOutlineSpans_test.go
Show resolved
Hide resolved
| } | ||
|
|
||
| func (l *LanguageService) addRegionOutliningSpans(sourceFile *ast.SourceFile) []*lsproto.FoldingRange { | ||
| regions := make([]*lsproto.FoldingRange, 0, 40) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
40 is the max depth that strada used, but I don't think that we actually need to prealloc these lists.
This doesn't panic anymore. |
|
This unfortunately crashed on me when I opened into |
|
Since I pushed, I can't review anymore. Can someone else look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 37 out of 37 changed files in this pull request and generated 2 comments.
internal/fourslash/tests/gen/correuptedTryExpressionsDontCrashGettingOutlineSpans_test.go
Show resolved
Hide resolved
|
On version I can provide you file, but not in a public thread :) |
|
Please file an issue with at least the panic stack trace. |
This PR implements folding ranges in the lsp. tsserver also had hint spans while lsp doesn't so I have combined those tests into folding tests.
Fixes #2176