language-tools
language-tools copied to clipboard
Svelte typescript plugin conflict with typescript-imba-plugin
Describe the bug
When Svelte for VSCode is enabled, the TS language server will crash 5 times, even if a Svelte project isn't open.
Reproduction
- Enable Svelte for VSCode
- Open any project
Expected behaviour
TS extension does not crash.
System Info
- OS: Windows
- IDE: VSCode
Which package is the issue about?
Svelte for VS Code
Additional Information, eg. Screenshots
The ts extension logs: https://pastebin.com/hLt97NxJ
The svelte extension logs: https://pastebin.com/vtE9eZvi
Can you follow this doc to get more verbose logging for the typescript server? Didn't see many useful messages in the log you provided and I can't reproduce it.
Hi! When trying to log it says that it hasn't started logging, however I found a bunch of recent logs in the output, as there were many I decided to just send the log folder logs.zip
Looks like it's the Imba extension that is conflicting with our typescript plugin. I will look into if there's anything we can do on our side.
Their typescript plugin use class to patch the projectService.host
of tsserver. But the original object is functional. Adding a Function.prototype.bind here can fix it. https://github.com/sveltejs/language-tools/blob/b87ea2e41c3b7b3fd83be006da588c8992db5a38/packages/typescript-plugin/src/svelte-snapshots.ts#L281
But I am not sure it is the fix. Because some other plugins might also be oppositely using the behaviour. Since it wasn't originally an object-oriented code that references this
. So the this
might be another object or global scope.
Edit. After realizing how we patch the host
object method. I don't think bind
is the fix. I think they should bind it on their side.
Hey. Author of the typescript-imba-plugin here. Tbh I definitely think you should call readFile
with the host as the target.
https://github.com/sveltejs/language-tools/blob/b87ea2e41c3b7b3fd83be006da588c8992db5a38/packages/typescript-plugin/src/svelte-snapshots.ts#L320
should be readFile.call(this.projectService.host)
instead. You can argue that the current readFile in the ts service does not use this
, but you are still patching and changing the value of this
for every other plugin that has to patch into the ts service. If you call it with the correct this
value - your patch is completely transparent for everything but svelte files, which is how it should be.
I will find a workaround for the imba-typescript-plugin on my end, but I still think this should be changed :)