Fold Types is a VSCode extension that provides commands to fold enabled types (classes, functions, arrays, etc...) recursively from any point in the document rather than folding levels to provide a more intuitive method of folding. Types can be enabled or disabled in the extension settings based on syntax (php, js, etc..) to match your desired folding needs.
When calling a fold-type command, enabled types will fold recursively leaving all other disabled types un-collapsed providing faster navigation to code that you are looking for. You can fold recursively throughout the entire document (fold all) or from within a single parent (fold parent/fold children) that will only fold enabled types recursively inside the parent leaving everything out side of it untouched.
There is no VSCode API to get fold points or types so syntax checking and pattern matching are all done manually. As a result, only certain languages (the ones I use) are currently supported.
- PHP (Mixed HTML, JS, CSS)
While this has been heavily tested to catch all patterns, there may be some outliers that fell through the cracks. If you notice something fold that shouldn't or something not fold that should please submit a bug request and I will look into it as soon as possible. Also if there is a language not supported and I get enough requests that make it worth the time to add I will take the time to learn the syntax and patterns and add them.
Example setting that demonstrates folding effect with "fold-types.php.class" set to false.
"fold-types.php.class" : false
With "fold-types.php.class" set to false, when the "fold-types.fold-all" command is executed, only the functions are folded leaving the class un-collapsed allowing for a faster, intuitive navigation to the code you are trying to find.
- Folds all enabled types recursively through out the entire document.
- Folds all enabled types recursively through out the parent block only as well as collapsing the parent its self.
- Folds all enabled types recursively through out the parent block only but leaves the parent block un-collapsed.
- Special command to ignore rules and fold all children recursively regardless of type leaving the parent block un-collapsed.
- Unfolds all types regardless of type inside the parent as well as unfolding the parent is self.
You can and should still use the existing editor.unfoldAll command to unfold the entire document.
How to use
Type "Fold Types" in the command palette to find the commands but its recommended you assign hot keys.
Fold Types comes configured with a few enabled types that I feel to be the most intuitive items to be folded but almost any type can configured to be folded or ignored based on your needs.
- fold-types.js.method (default enabled)
- fold-types.js.object (default enabled)
- fold-types.js.objectFunctionParam (Matches objects passed as parameters to functions)
- fold-types.js.objectObjectParam (default enabled) (Matches objects inside other objects)
- fold-types.js.array (default enabled)
- fold-types.js.arrayFunctionParam (Matches arrays passed as parameters to functions)
- fold-types.js.arrayObjectParam (default enabled) (Matches arrays inside other objects)
- fold-types.js.switchCase (default enabled)
- fold-types.php.method (default enabled)
- fold-types.php.array (default enabled)
- fold-types.php.arrayFunctionParam (Matches arrays passed as parameters to functions)
- fold-types.php.arrayObjectParam (default enabled) (Matches arrays inside other arrays)
- fold-types.php.for (Includes foreach)
- fold-types.php.switchCase (default enabled)
Only the most common tags have been included but if there are some that the community wants they can be added later.
- fold-types.html.tableTr (default enabled)
- fold-types.html.tableTd (default enabled) (Includes <th>)
- fold-types.html.idAttribute (default enabled) (Special: Folds any tag that has an id="" attribute set)
- fold-types.css.block (default enabled)
How to configure settings
The easiest way to configure enabled types is to right click on the extension in your extensions list and select "Extension Settings".