Skip to content

More powerful folding ranges API #827

@matklad

Description

@matklad

When VS Code folds the range, it just completely hides its contents:

image

When IntelliJ folds the range, it shows a certain replacement string instead:

image

The latter behavior is more flexible, and it would be cool if the protocol supported it. It allows for the following features:

  • folding a subrange in the string, which allows to hide boilerplate (see this post for example)

  • folded blocks take one line instead of two:

image

image

  • showing some important info from the fold, without making it more verbose:

image

To implement these features, we need to add two things to the protocol:

  • a replacementText?: string field to FoldingRange (this covers bullet points 1 & 2)
  • add a group?: number field to FoldingRange, such that all ranges in the group are folded-unfolded in lockstep. This covers use case 3, where { and } are separate folding ranges, linked into one group

However, I assume that the bulk of work here needs to happen on the editor's side as it seems like VS Code doesn't support such replacements yet.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions