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

auto-completion for css variables #521

Closed
pngwn opened this issue Sep 3, 2020 · 7 comments
Closed

auto-completion for css variables #521

pngwn opened this issue Sep 3, 2020 · 7 comments
Labels
feature request New feature or request Fixed Fixed in master branch. Pending production release.

Comments

@pngwn
Copy link
Member

pngwn commented Sep 3, 2020

Is your feature request related to a problem? Please describe.
CSS custom properties can have long names and are difficult to type. Even though their definitions are in random CSS files, it would be nice to get auto-completion on them. Having first-class language-tooling support for a theming solution that we are trying push as the best choice in most scenarios would really help with adoption.

Describe the solution you'd like
Obviously this feature would be impossible to implement without letting the language tools know where the CSS variables might be defined due to how CSS works. I imagine we could provide an array of filepaths telling the language tools where it should look for the definition of any CSS custom properties. Any custom properties found in that file (or those files, maybe a glob or regex?), regardless of selector, should auto-complete whenever a user types a qualifying set of characters. I imagine we could begin to match on available CSS vars whenever a user has typed var(.

Describe alternatives you've considered
Do nothing and be sad.

Additional context
If I could screenshot this feature I would not be asking for it!

@dummdidumm dummdidumm added the feature request New feature or request label Sep 4, 2020
dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Sep 4, 2020
Add option to set css files which will be checked for global vars which will appear in autocompletion
sveltejs#521
@dummdidumm
Copy link
Member

dummdidumm commented Sep 4, 2020

Where should these completions appear? Only inside <style> tags or somewhere else, too? (I guess for now only CSS, but I think there's some RFC proposing more possibilities).

@dummdidumm
Copy link
Member

dummdidumm commented Sep 5, 2020

Mhm it would also be cool to pick up definitions of global vars inside Svelte components. Determining what to show as autocompletion (respecting hierarchy) would be nice, but maybe a little too much right now.
Edit: Can be done by just adding a glob for svelte files. Then this gets picked up, too:

<style>
    div {
        --some-color: blue;
    }
</style>

dummdidumm added a commit that referenced this issue Sep 6, 2020
Add option to set css files which will be checked for global vars which will appear in autocompletion.
The watched files could be anything, so it could also be svelte files with global vars in their style tag.
Also added a change listener to the ConfigManager to get notified of config changes which removes the need to reload the language server after changes in this case.

#521
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Sep 6, 2020
@pngwn
Copy link
Member Author

pngwn commented Sep 6, 2020

Sorry, took me a little while to come back to this:

Where should these completions appear? Only inside <style> tags or somewhere else, too? (I guess for now only CSS, but I think there's some RFC proposing more possibilities).

Yeah i think for now, just in the style. I principle you could apply vars inline in style attributes too but I think just in style elements would be a good target for now.

@pngwn
Copy link
Member Author

pngwn commented Sep 6, 2020

And i also cannot fathom how you are quite this fast.

@pngwn
Copy link
Member Author

pngwn commented Sep 6, 2020

Regarding tracking global vars in parent components, that would be pretty amazing. I have no idea how this would work but if you think it is possible at some point, I certainly won't complain about the addition of such a feature.

dummdidumm added a commit that referenced this issue Sep 6, 2020
@dummdidumm
Copy link
Member

I'll leave it as is for now with only the tracking of global variables inside specified files. If the need arises, feel free to open another issue.

@yazonnile
Copy link

Hello, guys.
How can I make this option works?

I have a file ROOT/client/src/lib/styles/variables.css

:root {
  --mainColor: #0f2499;
}

I set client/src/lib/styles/variables.css as an value into option (Svelte-Plugin-CSS-Globals)
But nothing happens. No autocompletion.
When I type var(--mainCo) - no suggestions

dummdidumm added a commit that referenced this issue Dec 13, 2020
#521 
By making the label contain the `var`-part, it will show up more likely for users.
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 Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

3 participants