tree-sitter-swift icon indicating copy to clipboard operation
tree-sitter-swift copied to clipboard

highlighting keyword matching

Open mattmassicotte opened this issue 2 years ago • 4 comments

I noticed a highlighting issue with Swift sources, and have tracked it down to how the highlighting.scm file is set up. At issue is how some keywords are matched. As an example, consider the code snippet:

public exten

The visibility modifiers are only matched with the visibility_modifier node, so in this case public will not be highlighted. But, the grammar totally can recognize public at this point, despite the incomplete code.

I'd like to propose matching all keywords with their plain tokens. I believe this will both improve quality and performance of highlighting. However, this isn't a 100% trivial change to the scm file, so I wanted to check in first before opening up a PR.

mattmassicotte avatar Apr 20 '23 11:04 mattmassicotte

Thanks for asking, seems fine to me!

alex-pinkus avatar Apr 20 '23 13:04 alex-pinkus

Ok, so I actually got started working on this, and ended up having a pretty difficult time. It turns out that the highlights.scm on main doesn't compile.

At issue is the following line:

"await" @keyword

I tried tracking down what was up, but I don't fully understand what's going on in the grammar with it. I know nearly zero about grammars, but what is going on here?

_await_operator: ($) => alias("await", "await"),

mattmassicotte avatar May 04 '23 15:05 mattmassicotte

So that alias exists because without it, difftastic will skip highlighting any await keywords it sees, regardless of what we have in highlight queries. I wasn’t super sure what that Alia’s did but it fixed that bug.

I have highlight tests running on CI so some environment does exist where those queries compile. What version of treesitter are you using?

alex-pinkus avatar May 05 '23 06:05 alex-pinkus

And I finally have circled back to this. Sorry for dropping the ball. I've just updated to tree-sitter 0.20.9. This line in the highlights continues to fail to compile with a TSQueryErrorNodeType.

Commenting out that one statement allows the query to be parsed.

mattmassicotte avatar Jan 30 '24 16:01 mattmassicotte