2022-10-25

VS Code: avoid overaggressive parenthesis removal (in Scala / Metals)

I don't think this is a Scala- or Metals-specific issue, but that's where I'm seeing it.

VS Code aggressively removes parentheses, but not in a symmetric fashion. For instance, if I type the following:

Before image, two sets of parentheses

and I want to remove the inside parentheses, I would start by removing the inner closing parenthesis:

closing inner parenthesis removed

OK, the highlighting is already suggesting the problem: when I removed the inner parenthesis, it is the outer one that looks unmatched.

If I now go ahead and remove the inner opening parenthesis, both the opening and closing parentheses are lost:

mismatched with only opening outer parenthesis remaining


So maybe there is a right way to remove them that I am missing. Instead of removing the inside closing parenthesis, I will start by removing the inside opening parenthesis:

enter image description here

Unfortunately, in this case only the inner opening parenthesis is removed, so it is still mismatched.

Ugly Workaround

So for now, I either remove the inner closing parenthesis, then the inner opening parenthesis (which removes both, as shown), then I go back and add the lost closing parenthesis). Or, I remove the inner opening parenthesis, then go to the end of the line and remove that extra closing parenthesis.

Because I'll do this hundreds of times a day, the few wasted keystrokes really add up.

What did VS Code want us to do here? What is the right way to engage with its parenthesis autodeletion?



No comments:

Post a Comment