-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
[Feature request] Add Svelte support #39
Comments
Hey, yeah it's probably doable but I haven't worked with Svelte yet and even though I'd love to, I currently don't have the time. PRs are welcome 🙏 |
# Motivation To ease the review of PR and to improve our DX, automatically organize and sort the `import` # Changes - add [prettier-plugin-organize-imports](https://github.com/simonhaenisch/prettier-plugin-organize-imports) # Note - the plugin does not organize imports in `.svelte` [yet](simonhaenisch/prettier-plugin-organize-imports#39) but will do so in all other files (all `.ts` and `.spec.ts` files)
Hey @danielquintero I just released a new version where you can enable an option BWT if anyone knows a package similar to |
Looked into it a bit more and it does look like |
So I've tried I've also tried using typescript-svelte-plugin (by adding it to const sveltePlugin = require('typescript-svelte-plugin');
const tss = require('typescript/lib/tsserverlibrary');
sveltePlugin({ typescript: tss });
languageService = tss.createLanguageService(getLanguageServiceHost(filepath, readFileSync(filepath, 'utf-8'))); So at this point I'm not sure how to make a language service that can take a whole |
Came up with a PR ☝️ however I'm not very confident about it yet... if anyone would be able to test this out on their project, that would be really helpful! Clone the repo, checkout the |
See comments on the PR (now closed)... there must be a way to use a piece of svelte language tools programmatically to do import organizing correctly from this plugin, I don't know where to start though (I've skimmed through the source code but couldn't find anything). |
@simonhaenisch FWIW there are only 4 references to They are all in the Typescript provider, which makes me think the Svelte provider must extract the Typescript from Svelte along with some metadata about what imports are referenced by the component's HTML section, then the Typescript organizer returns an updated Typescript chunk. |
Reply from the Svelte Language Tools team: sveltejs/language-tools#1649 (comment) |
You can try to use @volar-examples/svelte-typescript. |
@johnsoncodehk thanks a lot for this! I just tried it after installing the latest versions (1.0.3), however I have a couple of problems... here's the branch diff: volar-svelte-support First problem is that prettier-plugin-organize-imports/lib/get-language-service.js Lines 14 to 19 in 23c0bcd
Second problem is that I get the following error when running the test:
I can prevent this error by doing prettier-plugin-organize-imports/lib/organize.js Lines 24 to 27 in 23c0bcd
However I've had the same problem before with Either way, calling |
I will check it later, but just have a quick look, why you don't use |
@johnsoncodehk not sure why but it's broken, doesn't contain the |
@simonhaenisch Sorry for delay, can you try v1.0.4-patch.1? |
@johnsoncodehk I just tried with latest (v1.0.8) and the "could not find source file" error is gone, thanks 🙏 But it's still the same problem that Maybe you can check my updated implementation at https://github.com/simonhaenisch/prettier-plugin-organize-imports/compare/volar-svelte-support. The changes are pretty minimal, just hooking into the svelte parser from |
Any progress on this? Looking forward to it :) |
Would love svelte support as well :) |
sry got stuck and then didn't have time to work on it anymore. Volar tooling has been moved to I'm happy to accept a contribution for this, I did some initial work in #80. |
Svelte support would be absolutely 🔥 |
If anyone is still looking for a robust alternative to sort imports: see these rules from eslint-perfectionist: |
I have used this plugin in Angular, React and Vue projects. Recently we started migrating a codebase to Svelte and I was eager to keep using this plugin for .svelte files... to my surprise there is no support for Svelte and actually I ran into issues where imports were getting removed when using svelte-language-tools + prettier-plugin-organize-imports...
Since there is Vue support for sfc, I think adding support for Svelte should be doable, right?
The text was updated successfully, but these errors were encountered: