tree-sitter-swift
tree-sitter-swift copied to clipboard
highlighting keyword matching
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.
Thanks for asking, seems fine to me!
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"),
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?
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.