Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlighting keyword matching #289

Open
mattmassicotte opened this issue Apr 20, 2023 · 4 comments
Open

highlighting keyword matching #289

mattmassicotte opened this issue Apr 20, 2023 · 4 comments

Comments

@mattmassicotte
Copy link
Contributor

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.

@alex-pinkus
Copy link
Owner

Thanks for asking, seems fine to me!

@mattmassicotte
Copy link
Contributor Author

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"),

@alex-pinkus
Copy link
Owner

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?

@mattmassicotte
Copy link
Contributor Author

mattmassicotte commented Jan 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants