helix
helix copied to clipboard
Rust: incorrect highlights of `pub macro` and `///` (doc-comment)
Summary
I've done a git bisect and both bugs exist long before the Tree-House migration, so I suspect the problem lies in TS-Rs grammar
Reproduction Steps
I tried this:
hx tmp.rs- Paste this into the buffer:
// this is needed for repro
fn f(){}
// prepending `pub` fixes the HL of the next `pub`
macro _const_assert {
($condition: expr, $const_msg:literal, $runtime_msg:literal, $($arg:tt)*) => {{
if !$crate::intrinsics::likely($condition) {
$crate::panic::const_panic!($const_msg, $runtime_msg, $($arg)*)
}
}}
} //`;` // fixes the HL of the lone `///`
// only if the previous `macro` has `pub` as well
/// A version of `assert` that prints a non-formatting message in const contexts.
///
/// See [`const_panic!`].
#[doc(hidden)] // attributes are needed to repro `pub` bug
pub macro const_assert {
($condition: expr, $const_msg:literal, $runtime_msg:literal, $($arg:tt)*) => {{
if !$crate::intrinsics::likely($condition) {
$crate::panic::const_panic!($const_msg, $runtime_msg, $($arg)*)
}
}}
}
I expected this to happen: pub is keyword; /// is comment.
Instead, this happened: pub is variable; /// is operator.
Helix log
~/.cache/helix/helix.log
Platform
Linux
Terminal Emulator
irrelevant
Installation Method
source
Helix Version
unknown
Even GitHub's highlighter has the same bugs, lol. Should I close this?
Looking at subtrees, it seems that there's some problem with parsing the macro which breaks how tree-sitter reads the rest of it?
Yeah this is something that will need to be handled in tree-sitter-rust. I think the macro keyword is relatively new addition to Rust so it probably hasn't been added in tree-sitter-rust yet. Also I believe GitHub uses tree-sitter-rust for syntax highlighting these days.
Yeah this is something that will need to be handled in tree-sitter-rust. I think the
macrokeyword is relatively new addition to Rust so it probably hasn't been added in tree-sitter-rust yet. Also I believe GitHub uses tree-sitter-rust for syntax highlighting these days.
How about switching to the tree-sitter-rust-orchad fork of tree-sitter-rust? It would fix this issue as well as support other features, like impl const
It seems to be more actively maintained:
If I recall correctly, imp const, or I guess impl ~const, was removed in an effort with a new RFC? Not sure that should be a thing in a grammar yet. But if it fixes other things I guess parsing other (random?) things could be fine?