5

After recently migrating to VS Code (MacOS), I've noticed that I can't collapse any case code blocks, something affecting all my switch statements.

Initial format:

switch (name) {
case 'a':
  ...
  break;
case 'b';
  ...
  break;
default:
  ...
}

What I've tried:

Indenting case and playing around with the indent setting in .eslintrc --- 2, { "SwitchCase": 1 } --- did no good:

switch (name) {
  case 'a':
    ...
    break;
  case 'b';
    ...
    break;
  default:
    ...
}

None of the other research I've done has gotten me anywhere. Assuming there's a way to change/fix this, how would I do it?

2
  • So you want to collapse case statements individually? Not the entire switch statement? Commented Feb 14, 2019 at 20:52
  • @ZackWalton - i want the option to collapse the entire switch statement, and each case block within, so both...
    – asw1984
    Commented Feb 14, 2019 at 20:58

2 Answers 2

4

You can fold switch statements in vscode by clicking the minus side near the line number of where the switch statement starts. Here is an example of what I mean https://code.visualstudio.com/docs/editor/codebasics#_folding

The issue I think you are having is that your Folding strategy is set to auto. If you set it to indentation then it should work for the case blocks. Try setting this in your preferences:

"editor.foldingStrategy": "indentation"
1

Another tip could be to use brackets to define the case:

switch(something){
    case "a": {
        //Your code here
        break;
    }
}

In this way the editor will always offer you the block folding.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .