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

Replace '; inherits <language>' in treesitter queries with <language> queries instead of appending them #2470

Merged
merged 2 commits into from
Jul 22, 2022

Conversation

Philipp-M
Copy link
Contributor

This enables the possibility to "inherit" a language later in treesitter queries file. It helps with prioritizing queries.

E.g. (the case why I looked into this):
In the typescript highlights query file this didn't work for me:

(internal_module "namespace" (identifier) @namespace)

for

declare namespace GreetingLib { }

(@namespace for GreetingLib)

because somewhere earlier in the javascript query this was defined

((identifier) @constructor
 (#match? @constructor "^[A-Z]"))

which is of course prioritized, as it is executed earlier.

To solve this particular example with this PR is by appending ; inherits: javascript at the end of the typescript highlight queries file (I might open a PR for better highlighting in javascript/typescript, likely soon).

The keyword "inherits" is a little bit ambiguous with this PR I guess, maybe we should rename it to something else like "imports" instead?

@the-mikedavis
Copy link
Member

I like this 👍

We would be diverging a bit from what other tree-sitter consumers allow but I don't see much potential for that to be bad in this case. If anything, we could contribute this upstream back to tree-sitter-cli.

@the-mikedavis the-mikedavis added the S-waiting-on-review Status: Awaiting review from a maintainer. label May 18, 2022
@the-mikedavis
Copy link
Member

I think "inherit" is still appropriate. It may be good to rename it to "inherit" rather than "inherits" since "inherits" sounds declarative and this PR makes inheriting imperative.

@archseer archseer merged commit b6c700f into helix-editor:master Jul 22, 2022
thomasskk pushed a commit to thomasskk/helix that referenced this pull request Sep 9, 2022
… queries instead of appending them (helix-editor#2470)

Co-authored-by: Blaž Hrastnik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants