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

support for svelte files #165

Open
ns740 opened this issue Dec 7, 2021 · 2 comments
Open

support for svelte files #165

ns740 opened this issue Dec 7, 2021 · 2 comments

Comments

@ns740
Copy link

ns740 commented Dec 7, 2021

please add support for .svelte files

i've kludged a fix in my copy of the plugin as suggested in issue 153
by copying the after/syntax/css.vim file to after/syntax/svelte.vim

this basically works on css that appears between <style></style> tags but i am not confident to submit this as a PR because it seems there is a more thorough and correct way to do this. (Should i use "runtime" and refer to the existing .css file instead? What about typescript in svelte files? - should the svelte config reference the typescript configs some way?). I am clearly out of my depth.

@ap ap added the enhancement label Dec 8, 2021
@ap
Copy link
Owner

ap commented Dec 8, 2021

A bit more info would be useful – until now I wasn’t aware of Svelte… which is presumably what you are asking about?

I find evanleck/vim-svelte and leafOfTree/vim-svelte-plugin for that – are you using one of those? If you have any sense of this, would you say they are both popular? Do people use something else?

Oddly, the way those plugins are constructed and the way CSS Color is built, I think it should be getting loaded automagically already, in which case your issue would be a bug rather than a feature request. But this is preliminary only as I haven’t done any testing yet and may find I was misremembering or overlooking something once I do.

@ns740
Copy link
Author

ns740 commented Dec 8, 2021

A bit more info would be useful

apologies

svelte files have html, javascript and css styling all together in one file.
javascript is between <script> tags and css is between <style> tags.

i am using the leafOfTree plugin. It sets the filetype to "svelte" and dynamically sets a subtype as the cursor moves through the file and fires an event OnChangeSvelteSubtype(subtype) when it changes. But the filetype is just set to svelte.

there is a note in the plugin readme:

filetype is set to svelte so autocmds and other custom settings for javascript have to be manually enabled for svelte.

which is what the "kludge" fix in the OP does (it cloned the css settings to create new svelte settings)

TBH i don't know enough about how this works and what other plugins (like linters?) are listening to that subtype event - it might be that vim-css-color doesn't need such precise tracking. I've been running with my "svelte.vim" setting hack which just treats a svelte file like a css file and the colors get interpreted just fine. There probably is an edge case where a javascript constant will look like a color and vim-css-color will argue with syntax highlighting but i haven't seen it yet. It's sort of working but doesn't seem like a clean, proper fix.

there are some the tricky things happening in the /after/syntax/*.vim files. Like "runtime" for example. there seems to be a lot of functionality there for reusing code from other filetypes. i might be able to help with a PR if i understood how these files work. And maybe the "right" way to do this is to only operate on the stuff between <style> tags. (Currently i'm clueless how to do this though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants