skip to Main Content

I’m trying to figure out the specific requirements (if it’s possible) that allows me to collapse/uncollapse a commented out block of code (written in javascript) in Visual Studio Code MacOS.

Please see the image:
image reference

I know {} makes collapsible blocks.

But would like to know how to make commented out collapsible blocks.

2

Answers


  1. Chosen as BEST ANSWER

    Edit: Found An Easy Solution: Highlight/Select block of code you want to manually collapse, open Command Palette (command + Shift + p), select: Create Folding Range From Selection. This will create a new folding range for your current selection. :) If you want to remove the folding range, then open up Command Palette again and select Remove Manual Folding Ranges on the selected block of code.


  2. Language provider extensions can register a FoldingRangeProvider which handles detecting patterns in code where it wants to provide folding regions. The behaviour of an extension is up to the extension. If you want to see the exact details, either find out by experimentation, or reading the source code of the extension.

    In the absence of a language provider that contributes a folding range provider, VS Code will provide folding ranges based on indentation (see also the editor.foldingStrategy setting).

    Users can use custom folding region comments to get arbitrary folding regions for ranges of lines.

    Related if you want to set a specific extensions’ folding range provider as the default folding range provider: the editor.defaultFoldingRangeProvider setting.

    For example, since you tagged your question as a javascript question, you can see the source code for the JavaScript extension for VS Code, which as far as I can tell, currently does not contribute a folding range provider, while the TypeScript extension does.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search