Reputation: 271
Visual Studio Code 1.24.1
While I was working on something today. It prompted me to do an update which I did (Update was to 1.24.1). I'm not sure if I hit a shortcut accidentally at about this same time or if this was caused by the update.
But I seem to no longer be able to use comments as a fold point.
However again, I'm not sure if I hit a shortcut of some sort, or if this was caused by the patch.
and my googlefu did not help me find an answer for visual studio code. Found many old topics about visual studio (prof not code) and for other editors. but couldn't find a topic specific to VSC.
I liked to use comments as fold points \ section headers.
Example of comments I used to use as fold points
Is this a bug in VSC 1.24.1 or did I hit a shortcut I'm unaware of?
Upvotes: 27
Views: 19011
Reputation: 41
VS Code has folding, but is dependent on language. For Javascript:
//#region
//#endregion
There is a nice table located in VS Code documentation.
Upvotes: 1
Reputation: 1748
VS Code has a method of marking the start and end of a region that can be folded and expanded easily. And also provide it a name/short description that'll always be visible.
I've tried this on Javascript code and I believe it'll work on any language in VS Code. And you can have anything in between the start and end of region - comments, few lines or code, entire functions.
In the absence of proper code folding, this is a pretty good work around that'll work for all languages on VS Code.
//#region <REGION NAME>
< You can put any type of code in here - some lines of code, functions or single or multi-line comments.
//#endregion
For python, simply omit the //
in the demarcation lines, since #
is a valid comment indicator:
#region <REGION NAME>
...
# any code goes here, including multiple comment lines
...
#endregion
I don't code in PHP but was able to fold the code like this. You can try other variations for other languages. For vs code the following keywords matter "#region " and "#endregion". Figure out a way to put these keywords as comments in your code and it will enable folding, what comes between these keywords does not matter. so feel free to play around:
<?php
#region <Any name that helps you>
ECHO "Hello!<br>";
EcHo "Hope this helps you.<br>";
#endregion
?>
Upvotes: 51
Reputation: 1758
A kind of hack I found for react is using empty tags for example
<>
{/*
Your commented code
*/}
</>
This allows you to fold the commented code between the empty tags. You can go a step further and add regions as mentioned in the other answer to add some kind of description to it
Upvotes: 4