coder_uk
coder_uk

Reputation: 787

Visual Studio Code: prevent it from deleting code that is not needed

I've noticed that when I add a line that makes the subsequent lines redundant (like a continue in a loop, or a return), VSCode goes and deletes all subsequent lines - the ones which never run.

As an example, putting the continue; line in means the rest is no longer needed and so gets deleted by VSCode:

for (let i = 0; i < myArray.length; i++) {
   console.log('Loop: ' + i);
   continue;
   var thisWillBeDeleted; // ... but I do not want it to be
}

I get it's trying to be helpful and of course in my silly example above, it would be. Is there a way to stop it doing that though? Preferences? Extensions?

There are times when I'll just manually stick a continue in to break a loop to try running it, while debugging, accidentally save, and then have to retrieve all the code it then auto deletes below that line - which I actually do want to keep - but it went and got rid of assuming my hack was permanent.

It's not a disaster but gets a bit annoying.

Upvotes: 3

Views: 1520

Answers (2)

Guilherme Zago
Guilherme Zago

Reputation: 1

I was getting an error similar to yours, I'm just commenting here because I think other devs may bump into this and your answer helped me, but in my case the extension that was f**king up was the Prisma NextJS, after disabling it everything went back to normal.

Upvotes: 0

coder_uk
coder_uk

Reputation: 787

Ah ... I eventually figured it out. In case anyone else comes across this, it's the Beautify extension. Maybe it's a feature. Or maybe a conflict with some other combination of extensions. Either way, disable that, problem solved.

Upvotes: 3

Related Questions