Hello Stackoverflow community,
This is my first post here. I am using VS Code and am currently looking for a way to enable method and function folding by default like the feature available in PHPStorm. I looked around here and found some posts showing that you can fold all of the code or indentation levels as described here: https://stackoverflow.com/a/30077543/10713286
However, I am looking for a way to fold functions and methods using matching brackets as the folding method rather than indentation or use of //#region
and //#endregion
. Ideally, this could be the default and I could unfold the code as needed. PHPStorm does this beautifully and leaves the documentation method and function comments unfolded as an option. I am thinking this may need to be done by writing an extension. I am having trouble finding a way to do this though. I pulled the VS Code git repo and ran some grep searches to find that the folding method (for php) is set in vscode/extensions/php/package.nls.json:3
. There are #region
and #endregion
settings in vscode/extensions/php/snippets/php.snippets.json
on lines 243 and 250. The problem is that the folding is set with regex and I can't find a way to match brackets using regex alone.
This is an important feature for me because I am learning a new code base and having function/method folding really improves readability of large files. I can quickly scan for what I need and expand as needed. VS Code tries to do this, but if there are any lines intentionally outdented in a function, to make a comment more obvious for example, VS Code stops folding there rather than going to the end of the function. Any help on this issue is greatly appreciated!!
tldr; I need to find a way to fold code based on matching brackets rather than indentation in VS Code.