tree-sitter / tree-sitter-css

CSS grammar for Tree-sitter
MIT License
85 stars 34 forks source link

Classes and property keys both get `@property` group #34

Closed chrisgrieser closed 1 year ago

chrisgrieser commented 1 year ago

This is noticeable when comparing the default css highlighting with the one from this TS parser:

default css syntax highlighting

Pasted image 2022-11-17 00 41 15

TS css parser

Pasted image 2022-11-17 00 42 54

the white color is simply a color scheme issue – the parser issue is that both, the classes in the selector and the property, both get the same group @property, which I checked with TS playground:

Pasted image 2022-11-17 00 44 41 Pasted image 2022-11-17 00 45 10

Overall, this leads to worse syntax highlighting, regardless the theme.

sammce commented 1 year ago

Just writing to +1 this. I'm pulling my hair out trying to get it to look nice in .svelte files with the Dracula theme. If I could figure out how to use the default syntax highlighting for css in the <style> tag I 100% would.

samhed commented 1 year ago

Same, for this reason, I disable highlights for CSS. Is there any way I can help to get this resolved?

Astanusic commented 1 year ago

Got the same issue, if there is any way I can help to fix this I'm up.

UPDATE:

Got it working by introducing new queries in the highlights.scm file and by affecting them a hl group. I need to find where queries and hl groups are being matched so I will able to fix it.

samhed commented 1 year ago

Sounds great @Astanusic! I'm happy to test your changes once you have a patch available.

samhed commented 1 year ago

@Astanusic do you have a fix you could share? Is there anything I can do to help?

chrisgrieser commented 1 year ago

@amaanq Sorry to bother you, but may I ask what the reason is for this issue to be closed as "not planned"?

css is the only language I use where I am disabling treesitter highlighting because the colors are currently worse with it, and there seem to be several people who agree.

lucario387 commented 8 months ago

As this seems neovim-specific, let's cook up a version inside neovim first, shall we? Yes, nvim-treesitter is closely following (almost carbon copy of) tree-sitter-css highlight queries for captures. That doesn't mean it can't change. If you want the highlights to change, be the change you want to have :smile:. The queries were created 3 years ago, so not only the "default" captures have changed, so is the perception of what is better or not. So let's change the capture and pitch a PR for that.

chrisgrieser commented 7 months ago

Looks like the issue got fixed: https://github.com/nvim-treesitter/nvim-treesitter/commit/505a0e74cb82dfd1938dcc0eb2526c24abc345e2 🥳

samhed commented 7 months ago

Hm, @chrisgrieser do you know if we need to wait for some other part to update for us to benefit from the fix in https://github.com/nvim-treesitter/nvim-treesitter/commit/505a0e74cb82dfd1938dcc0eb2526c24abc345e2?

With nvim-treesitter updated to 8166080 I still get shitty CSS highlight colors: Screenshot from 2024-01-24 16-26-52

Does things work for you?

chrisgrieser commented 7 months ago

@samhed It looks fine on my end. Didn't do anything other than upgrading nvim-treesitter and then updating the parser. Pasted image 2024-01-24 at 16 34 53@2x

Have you updated the parsers via :TSUpdate after the nvim-treesitter-update? Maybe reinstalling the css parser could fix the issue, if there is something stuck? Otherwise, I guess you'll have to report a bug at nivm-treesitter.

amaanq commented 7 months ago

sorry for not responding before @chrisgrieser I forgot about this but yea this was an issue in nvim-treesitter (not here) that got resolved

Locking since it's unrelated, any other issues like this should be reported to nvim-treesitter, this is for the parser