microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.71k stars 29.08k forks source link

[folding] Allow to fold all method bodies #128912

Open matklad opened 3 years ago

matklad commented 3 years ago

When reading the code, it's very useful to fold function and method bodies: this gives you a quick outline of the file, with the ability to easily drill down specific function if you want to. It would be useful to have a "Fold all bodies" action to achieve that, similarly to how we already have "fold all block comments" and "fold all regions".

To give a specific example:

Unfolded:

image

Bodies folded:

image

Not that this can't be achieved "fold level 2", as not all bodies are at level 2, and not everything that is at level two is a function body.

API wise, it seems rather straightforward -- just add a "body" fold kind, and then let the language servers fill that out.

vscodebot[bot] commented 3 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

matklad commented 3 years ago

As an extension, it also would be useful to add a setting to fold bodies by default, a-la intellij:

image

aeschli commented 3 years ago

The folding infrastructure currently doesn't know where the method bodies are. We don't have an API for folding providers to communicate this (the same way as for comments and imports)

matklad commented 3 years ago

Just to clarify, the "API" for this would be adding one more value to already existing https://code.visualstudio.com/api/references/vscode-api#FoldingRangeKind.

aeschli commented 3 years ago

Correct.

tlemo commented 1 week ago

I'd love to see this finally happening, ideally the fully automatic variant: https://github.com/microsoft/vscode/issues/33449

dubeg commented 1 week ago

It's odd that Visual Studio doesn't have this feature either, I guess Microsoft devs just don't see the point in having that :/

rrmistry commented 1 week ago

This feature request made me think of this extension that does something similar but in a different language

https://marketplace.visualstudio.com/items?itemName=moalamri.inline-fold

Is it possible to do the same for Rust in an extension (maybe via a good Regex expression) , not relying on any new VS Code APIs?

emilyyyylime commented 1 week ago

wouldn't even be overly complicated thanks to Rust having a dedicated fn keyword; just needs to avoid false positives in comments/strings, and properly parse the return type (which could potentially contain semicolons and curly braces)

...okay it might be a bit complicated, and probably way harder for other languages. This definitely seems like a missing feature of the core LSP protocol. Some other easy fold kinds would be module and type/class