Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use external typescript-plugin for IntelliSense within svelte files #905

Open
sastan opened this issue Mar 22, 2021 · 9 comments
Open

Use external typescript-plugin for IntelliSense within svelte files #905

sastan opened this issue Mar 22, 2021 · 9 comments
Labels
feature request New feature or request limitation Constraints of the existing architecture make this hard to fix

Comments

@sastan
Copy link

sastan commented Mar 22, 2021

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?

@dummdidumm Mentioned that it is maybe possible to hook into the Svelte language server. How would that be done?

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?

Originally asked here: #580 (comment)

@dummdidumm
Copy link
Member

I haven't tested this but maybe it's enough to add it to the compilerOptions of the tsconfig.json. If not, I'm not sure currently how to integrate it. Plugins are editor-only, so for example tsc also does not use them. In the Svelte language server the TS code is already loaded by the time the tsconfig is read, so maybe that's too late.

@sastan
Copy link
Author

sastan commented Mar 24, 2021

What I want to achieve is autocompletion for the class attribute and tw function calls (in template and script blocks).

I could use a RegExp to "parse" but if there is a way to can an AST that would be awesome. I could then re-use some logic I have in the typescript-plugin.

Is there any way to communicate or hook in to the Svelte language server?

@bluwy
Copy link
Member

bluwy commented Jul 13, 2021

I found this StackOverflow question which was able to get typescript plugins running in the instantiated ts language server. I however can't find any bits in the source code where this logic could fit in. I too have a typescript plugin that I hope to work in Svelte files.

@dummdidumm
Copy link
Member

dummdidumm commented Jul 13, 2021

The language service is initialized here

Note to self: It needs to be checked what happens if the Svelte plugin is enabled, it could interfere with some of the language service functionality.

@dummdidumm dummdidumm added the feature request New feature or request label Jul 13, 2021
@bluwy
Copy link
Member

bluwy commented Jul 15, 2021

Did some more digging today, and I might have to conclude that it's impossible to load plugins just with a typescript language server. By just looking at a ts plugin's create(info) function, the info object contains a lot of properties that an instantiated typescript language server isn't enough to provide. For example,

interface PluginCreateInfo {
        project: Project;
        languageService: LanguageService;
        languageServiceHost: LanguageServiceHost;
        serverHost: ServerHost;
        config: any;
}

Also from the typescript-language-features extension, it seems that they load the plugins like this.which spawns a ts node server and let the server handle everything.

In turn, I looked into how typescript loads it, and by painstakingly walking up the call stack, it seems that it requires at least a "project" to load a plugin.

I'm not sure if it's a flawed or intentional design, but it sucks :/

@aradalvand
Copy link

aradalvand commented Jan 12, 2023

Aren't there any plans to add support for TypeScript plugins? Have things changed by any chance since this comment?

It would really be an immensely useful new feature. This is a pretty big thing that's currently lacking.

@jasonlyu123 jasonlyu123 added the limitation Constraints of the existing architecture make this hard to fix label Feb 21, 2023
@enyo
Copy link

enyo commented Feb 24, 2024

@dummdidumm do you know if this will be possible in Svelte 5? Is there a chance that this could work some day?

@jasonlyu123
Copy link
Member

The problem isn't something to do with svelte core. So no, it won't be possible in Svelte 5.

Is there a chance that this could work some day?

Maybe. The problem is explained in previous discussions. The object required simply doesn't exist in the Svelte language server. The situation has changed slightly in the later TypeScript version. The "typescript" import now has the necessary class(Project) that is needed but creating the object is considered an internal API for typescript. And we'll have to migrate our code that does similar things to the Project class. This won't be easy.

@aradalvand
Copy link

aradalvand commented Feb 29, 2024

Just stumbled into this again. Using things like gql.tada is not possible in Svelte today either; since its TypeScript plugin would work in neither .svelte files nor +page.ts/+layout.ts files. Huge, huge bummer :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request limitation Constraints of the existing architecture make this hard to fix
Projects
None yet
Development

No branches or pull requests

6 participants