microsoft / microsoft/language-server-protocol

Support folding range groups and "hoist to single line"-folding ranges

Open
#1,932 0 comments 0 reactions 1 assignee View on GitHub

@aeschli is already working on this.

Since May 6, 2024.

feature-request folding ranges
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.