The language-server has quite a few features by now. What's missing for the complete developer experience and intellisense though is crossing the boundaries of Svelte and JS/TS files. This can be achieved through a TypeScript plugin. The following features would be cool to have:
Dumping some thoughts:
getDiagnostics need to be synchronous. This is not possible to do right now since we use source-map which asynchronously generates a SourceMapConsumer. So either we switch the library or we do some kind of "use latest processed if available"-logic. What we definitely cannot do is reuse the language server connection and do requestX, await response.In the client inside extension.ts, add typescript/javascript as languages to deal with. Add logic to not active if it's not a Svelte project. Enhance the language server to deal with events from TypeScript and JavaScript files, too. This means things like "don't return usages from TS/JS files when find usages was triggered in a TS/JS file, as these will be shown twice then" or "route textdocument change events to DocumentManager only if it's a Svelte file". This will not solve the diagnostic errors problem because we cannot silence the TS server. It also doesn't work for rename because VS Code seems to go through the extensions one by one and stop at the first one providing rename functionality, which is the TS server - that's kind of a showstopper because this is likely the most valuable addition. Go to definition/find references/autocompletion/hover would work.
Hey I worked on a proof of concept today
https://github.com/pushkine/ts-plugin-svelte/
Beside obvious bugs where everything gets stale this doesn't yet work with Components, might be a conflict with declare global module "*.svelte" or some tweaking to do with svelte2tsx
Looks good to me though, what do you think ?
This is a nice POC!
I though about this topic a little more and there are to me two ways to get to a solution:
source-map with sync sourcemap-codec + own litte mapping function similar to how I did it in this ESLint plugin PR. Optionally reuse that logic in that PR to simplify+fix our mapping logic (could solve #666)source-mapSteps 1/2 can be done in parallel, the others are best done one after another. If someone wants to help in one of these steps, please ping here so we can coordinate. Step 5 is best done by me or @jasonlyu123 because we know the code base best and this is a critical part.
Advante: A "real solution"
Disadvantage: Especially "get generated position from original position" is likely much slower. Fortunately, we don't have to do this often.
svelte2tsxAdvantage: We keep the language server as-is mostly
Disadvantage: Incomplete "diagnostics"-solution? Will this work for rename?
This is a combination of option 1 and 2: Create a TS plugin which converts Svelte files through svelte2tsx and uses sourcemap-codec + custom mapping logic to get original positions. It will reimplement some of the logic inside the language server, which on one hand is some duplicated work, but it will keep the plugin clear of all additional logic/workarounds that are only needed within Svelte files.
Advantage: Separate, clean implementation
Disadvantage: Duplicated work
=========
Right now I think I prefer option 3. What do others think?
I also prefer option 3. Maybe we can export some functions from the plugin package or create another utility package to reuse some logic. For example, svelte-sys, source mapping utility, and source mapping workarounds.
First: Thanks for all the great work you are doing! You are creating a really good DX.
Now to the question:
I have created a typescript plugin that powers Twind IntelliSense for VS Code.
Is it possible or would it be possible to have the completions/diagnostics from that typescript plugin within svelte files using the same implementation?
I'm happy to contribute if there needs something to be implemented here. Or could give me some pointers/ideas on how that could be implemented in userland?
If this is the wrong issue I will move that into a separate issue.
Thanks for your time.
Thanks for the kind words! This question is unrelated to this issue. This issue is about implementing a TS plugin for Svelte. What you want is to hook into the Svelte language server. Please open a separate issue for that.
Most helpful comment
Hey I worked on a proof of concept today
https://user-images.githubusercontent.com/30108880/107896725-6e56d180-6f37-11eb-8ac9-fff759572208.mp4
https://github.com/pushkine/ts-plugin-svelte/
Beside obvious bugs where everything gets stale this doesn't yet work with Components, might be a conflict with
declare global module "*.svelte"or some tweaking to do withsvelte2tsxLooks good to me though, what do you think ?