Skip to content

Generalized Folding Rules #138093

Description

@PieterBranderhorst

I'm working with some languages where I'd like to have code folding available. Indent based folding with markers is little help because, to put it kindly, there's a lot of technical debt in that code. And some of the syntax relies on column 1. I'd rather have a parameter driven solution than write language specific providers.

I've spent some time thinking, looking at what other editors do, looking at past questions here about folding. I have a suggestion for an approach. I've written code to implement it in vscode to at least demonstrate viability. If the code isn't isn't wanted I'll work on releasing it as an extension. But like the recent bracketing work it will run best if built-in I think.

I ended up thinking that generalized folding doesn't fit perfectly with language syntax trees. Folding has considerations for line breaks, comments, blank lines. And doesn't necessarily require a language syntax - it may be useful to loosely define folding for some report text, log files, etc.

I think generic folding should support "block folding" for blocks which have a defined start and end, "heading folding" for things like chapters and sections which only have defined starts, and "group folding" where one wants consecutive lines with a particular pattern to fold as a group.

The code I've written is faster than the existing indent based folding code, way faster than the default typescript folding provider, and doesn't use much memory. It is respectful of user response time, slicing up work which could otherwise hog the cpu with very large files. (See the "TimeSlicedPromise" class in the code for that part. I didn't find something like it in vscode so I added it. It might be useful elsewhere.)

Please visit this page for more details. I hope this will be of interest.

Metadata

Metadata

Assignees

Labels

*out-of-scopePosted issue is not in scope of VS Codeeditor-foldingEditor code folding issuesfeature-requestRequest for new features or functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions