I'm experiencing an issue where "unreachable code" in a Vue/TypeScript file is automatically deleted on save. (A pretty shocking behaviour, often I'm temporarily adding a "return false" early in a function during debugging, I'd never expect the rest of the function body to be deleted!)
Through a process of elimination I have discovered that disabling either the "Vue - Official" or built-in "TypeScript and JavaScript Language Server" extension disables the behaviour, so presumably they are collectively the culprit.
I have found a way to prevent this by adding this to my settings.json:
"editor.codeActionsOnSave": {
"source.fixAll": "false"
},
But this is a big hammer to use. I would like to disable this just for the Vue extension.
I can't find any proper documentation on editor.codeActionsOnSave but from various references around the place, I'd expect this to work:
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.fixAll.vue": "never",
},
or
"source.fixAll.typescript": "never",
however, it does not. The source.fixAll setting by itself works, but source.fixAll.vue does not seem to have any effect, whether or not source.fixAll is present (and same for typescript).
How can I achieve this?
Also, ideally, how can I disable just this one specific behaviour, without disabling other code fixes from the Vue extension?
EDIT
Hmm, "source.fixAll.ts": "never" does work, but I'm still wondering: is it the TypeScript extension itself that is doing the heavy-handed "fixing", or something else? How can I find the real culprit?
By enabling logging for the TS Server, I see this:
Info 790 [11:36:27.518] response:
{"seq":0,"type":"response","command":"getCodeFixes","request_seq":20,"success":true,"body":[{"fixName":"fixUnreachableCode","description":"Remove unreachable code","changes":[{"fileName":"[redacted]]","textChanges":[{"start":{"line":86,"offset":1},"end":{"line":89,"offset":1},"newText":""}]}]}]}
Info 791 [11:36:27.624] request:
{
"seq": 21,
"type": "request",
"command": "updateOpen",
"arguments": {
"changedFiles": [
{
"fileName": "[redacted]]",
"textChanges": [
{
"newText": "",
"start": {
"line": 86,
"offset": 1
},
"end": {
"line": 89,
"offset": 1
}
}
]
}
],
"closedFiles": [],
"openFiles": []
}
}
I think this means the TS extension itself is the one doing the "fixing"?