language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Svelte typescript plugin conflict with typescript-imba-plugin

Open SkyfallWasTaken opened this issue 2 years ago • 5 comments

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

image The ts extension logs: https://pastebin.com/hLt97NxJ The svelte extension logs: https://pastebin.com/vtE9eZvi

SkyfallWasTaken avatar Apr 23 '22 12:04 SkyfallWasTaken

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.

jasonlyu123 avatar Apr 24 '22 00:04 jasonlyu123

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

SkyfallWasTaken avatar Apr 24 '22 08:04 SkyfallWasTaken

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.

jasonlyu123 avatar Apr 24 '22 14:04 jasonlyu123

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.

jasonlyu123 avatar Apr 25 '22 01:04 jasonlyu123

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 :)

somebee avatar Jul 22 '22 12:07 somebee