tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter
MIT License
340 stars 97 forks source link

Macro highlighting failing after update #134

Closed lmburns closed 1 year ago

lmburns commented 2 years ago

I'm unsure when this happened in the commits, I have treesitter update everyday, so I believe it has been since last night. I'm also unsure if this has to do with this repo or the main treesitter repo. However, attribute-macros no longer highlight with my code. #[derive(...)] does, but #[serde(...)] does not.

The highlight group under #[derive(...)] is the following:

# Treesitter
* **@variable** -> **rustTSVariable** -> **TSVariable**
* **@function.macro** -> **rustTSFuncMacro** -> **TSFuncMacro**
* **@_name** -> **rust0** -> **0**
* **@_name** -> **rust0** -> **0**
* **@_name** -> **rust0** -> **0**
* **@_name** -> **rust0** -> **0**
* **@_name** -> **rust0** -> **0**

The highlight group under #[serde(...)] is the following:

# Treesitter
* **@variable** -> **rustTSVariable** -> **TSVariable**

Picture to show an example: Alacritty_2022-03-11_19-54

ninevra commented 2 years ago

@aryx This looks to me like the intended effect of #93? #[serde()] is not a built-in macro, so #93 causes tree-sitter to parse it as an attr_item rather than a meta_item, which, being a new node type, is presumably not highlighted (I'm not at all familiar with how syntax highlighting with tree-sitter works, sorry).

Avoiding this kind of breaking change while supporting non-meta-item attributes would probably require a different approach than #93, probably using injections as @resolritter suggested in https://github.com/tree-sitter/tree-sitter-rust/pull/93#issuecomment-747863610.

aryx commented 2 years ago

It's not highlighted because highlights.scm needs to be updated to take into account the new attr_item construct?

ninevra commented 2 years ago

Maybe? I don't see anything in highlights.scm (nor in the other queries) that looks like it handles the internal structure of attributes at all. There's just:

(attribute_item) @attribute
(inner_attribute_item) @attribute

Are there any tests for syntax highlighting, or an example of how best to write such tests?