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

add highlight support for tree-sitter-query language (tsq) #845

Merged
merged 4 commits into from
Oct 16, 2021

Conversation

the-mikedavis
Copy link
Member

@the-mikedavis the-mikedavis commented Oct 15, 2021

There's a tree-sitter parser for the .scm query DSL tree-sitter/tree-sitter-tsq and this PR adds it to the languages, along with highlight queries. Afaik there isn't an LSP for it though.

Here's what the highlights look like when highlighted by themselves 😄

tsq-highlights

(gruvbox theme)

Here are some other examples from more complicated highlights...

The current Elixir highlights (with plenty of fields):

elixir-highlights

Nix highlights which use a few of what I have scoped as @operators

nix-highlights

Notably it does (gracefully) fail to parse an escape_sequence in a regexp in the java (edit: and php) highlights:

java-highlight-fail

But I think that's intended behavior: that regex should be "^_*[A-Z][A-Z\\d_]+$" in order to be interpreted correctly (separate PR incoming). It happens correctly highlight constants with digits because of the missing $ at the end.

(there's a similar regex in the ruby (1) and javascript (2) highlights:)

((constant) @constant
 (#match? @constant "^[A-Z]\\d_]+$"))

([
    (identifier)
    (shorthand_property_identifier)
    (shorthand_property_identifier_pattern)
 ] @constant
 (#match? @constant "^[A-Z_][A-Z\\d_]+$"))

The scope names in the highlights are pretty subjective and I'm certainly open to debate on all of them :)

@archseer
Copy link
Member

This is great too! 👍🏻

Now all we need is a function to print out token trees to a document for debugging and it would make highlights very easy to develop :)

.gitmodules Outdated Show resolved Hide resolved
@archseer archseer merged commit e069fb9 into helix-editor:master Oct 16, 2021
@the-mikedavis the-mikedavis deleted the tree-sitter-tsq branch October 16, 2021 20:53
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

Successfully merging this pull request may close these issues.

None yet

2 participants