microsoft / microsoft/language-server-protocol
Support folding range groups and "hoist to single line"-folding ranges
@aeschli is already working on this.
Since May 6, 2024.
- Dominant language
- TypeScript
- Stars
- 13k
- Forks
- 1k
- Avg merge
- 6d 1h
- Merged PRs (30d)
- 10
Description
Hi
Like #1779, I would like to see improvements to the folding range support. However, I decided to file this one a a separate issue, because it would need more than defining more folding range kinds.
I would also very much like to see the "hoist small function to single line"-folding range. As an example, JetBrains IDE supports folding
public void setFoo(String foo) {
this.foo = foo;
}
into:
public void setFoo(String foo) { this.foo = foo; }
In the JetBrains IDE, this is done by emitting two folding ranges. The first for the start brace and one for the end brace and their related whitespace (notably the newline). In this example, marked by [...] ranges with the original content inside the [...].
public void setFoo(String foo)[ { \n ]this.foo = foo;[\n }]
The two folding ranges are then defined to related, so that the editor knows that that should expand/fold at the same time. The "two range" approach could have been replaced by a single range. However, the folding range text is not rendered as code. That is, syntax highlighting is lost. I think that would equally be true for most LSP clients since the collapsedText attribute is defined as text (and not stylish-able code - also, even then, it would be a layer violation for the folding range code to figure out how to highlight one line of code, no matter if it is in the server or the client).
This "two range"-mode example shown above would require the client to announce FoldingRangeClientCapabilities.lineFoldingOnly=false to be possible (making the dependency explicit).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.