phptools-docs icon indicating copy to clipboard operation
phptools-docs copied to clipboard

Could you fix the indentation of switch-case?

Open php4fan opened this issue 8 months ago • 3 comments

Microsoft doesn't seem to have any interest in fixing VSCode's idiotic default indentation of switch/case statements: https://github.com/microsoft/vscode/issues/174667

they marked it as a feature request and closed it as not planned.

Maybe the extension could override it? Actually I'm surprised it doesn't already, just like it improves many other aspects of formatting that VSCode does poorly.

Image

php4fan avatar Mar 19 '25 17:03 php4fan

We try to override it by providing "format-on-type" feature.

After typing ;, :, or }, our formatter re-indents the line and the corresponding code:

Image

jakubmisek avatar Mar 19 '25 17:03 jakubmisek

I disabled format-on-type long ago. I hate when the code moves around as I type.

I also hate when indentation gets adjusted after I've started typing instead of when I start a new line. Now I remember when I used to have format-on-type enabled, a lot of times I would fix the indentation myself before realizing/remembering that I just had to go on typing until the ":".

And then there are the cases where I adjust the indentation to my liking, type something, and it changes it back (I think that was the main reason I removed format-on-type).

I remember this coming up in other issues. Relying too much on format-on-type is not a good strategy.

php4fan avatar Mar 19 '25 17:03 php4fan

I understand;

So far, it's the only way I can think of that will fix the indentation of case, and it's also the typical approach (phpstorm and other IDEs behave the same way).

"format-on-type" fully respects your formatting settings/codestyle, so it should all play together nicely.

Sadly, I have nothing else to suggest. If we "HACK" VSCode to unindent after break; within switch, it may be unpredictable and buggy (because of technical reasons of how VSCode handles input).

jakubmisek avatar Mar 19 '25 17:03 jakubmisek