betterer icon indicating copy to clipboard operation
betterer copied to clipboard

Extension: When working with typescript, use existing `tsserver` or create new one

Open abrenneke opened this issue 4 years ago • 5 comments
trafficstars

Basically, the idea is instead of spinning up a typescript compiler for every single rule run, there's a single tsserver running in the extension that is reused for all typescript operations, the same way that the internal syntax checking in VS Code works.

In theory this would speed up any typescript operations by a lot, because the tsserver instance could cache everything and use a Watch compiler, but is also means a lot more development work on the betterer extension server side for a single use-case of betterer.

I suppose in theory, running betterer on the command line could spin up a single tsserver for all typescript operations too. We're probably an edge case for having more than one typescript rule in our .betterer file, but I think that would still improve times if the two rules could use the same server.

Just an idea!

abrenneke avatar May 10 '21 16:05 abrenneke

This would be great, but I have no idea how to make this happen in VS Code. I've explored their docs a bit, but it's unclear if it's even possible!

phenomnomnominal avatar Jun 11 '21 19:06 phenomnomnominal

yeah I was looking at the code for svelte-language-server as a reference, looks like it's a whole lot of boilerplate to get a server process being reused.

abrenneke avatar Jun 11 '21 19:06 abrenneke

Ooh that could be okay though, the extension is already pretty wild so a bit more doesn't make much difference. Could you point me to the bit in their code that does it?

phenomnomnominal avatar Jun 11 '21 19:06 phenomnomnominal

It seems like svelte has its own language server that then wraps tsserver et al.

Looks like

  • The extension boots up the svelte server: https://github.com/sveltejs/language-tools/blob/master/packages/svelte-vscode/src/extension.ts#L57-L145
  • The svelte server boots up and connects to vs code: https://github.com/sveltejs/language-tools/blob/master/packages/language-server/src/server.ts#L82-L128
  • Language server starts up a ts LanguageServerHost: https://github.com/sveltejs/language-tools/blob/master/packages/language-server/src/plugins/typescript/service.ts#L88-L153

Overall pretty dang complicated

abrenneke avatar Jun 14 '21 19:06 abrenneke

Oof. Scary 😅 . Might come back to this on a rainy day!

phenomnomnominal avatar Jun 14 '21 22:06 phenomnomnominal