tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some code is not highlighted correctly

jorendorff opened this issue · comments

Some folks noticed that GitHub's code highlighting for Rust recently regressed. Some examples are

  • not highlighting async as a keyword in

    pub async fn foo() {}
  • highlighting the two match arms differently in

    impl Lower {
        pub fn lower(&self, stmt: &Stmt) {
            match &stmt.node {
                RawStmt::Read(e) => self.lower_read(e),
                RawStmt::Print { expr, kind, newline, } => self.lower_print(expr, *kind, *newline),
            }
        }
    }

The cause of the regression is that GitHub recently switched from Linguist to tree-sitter-rust for Rust code highlighting.

The first bug is a one-liner in queries/highlights.scm. The second bug is more complicated. Part of it is due to handling (identifier) and (scoped_identifier) but not (type_identifier) and (scoped_type_identifier), but after that, it's probably impossible to distinguish names of struct-like enum variants from names of structs in (struct_pattern) using this pattern language. So whether we highlight them as enum variants (which would be correct in this example) or as type names, we'll be wrong sometimes.

For future reference, here's what these look like now:

The first example from the above text, with async not hilighed
The second exaple, with both match arms hilighed differently