-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
queries/nix: add injection rule for python test scripts, fix rules #5815
queries/nix: add injection rule for python test scripts, fix rules #5815
Conversation
This adds a missing injection rule for the NixOS VM test scripts written in However, I could not get this rule to apply without commenting the one that Re-ordering the rules in the file does not seem to change anything either. Is there a way to set some priority on the rules? This would also be useful to allow the comment rule to take precedence, so that (CC past file committers: @nrdxp, @the-mikedavis, @farwyler) |
Here's an example of the issue I'm observing due to the lack of { pkgs, ... }:
{
# highlighted as python as it should ("writePython3Bin" rule)
package = pkgs.writers.writePython3Bin "test" { } ''
from sys import stdin
print(i**2 for i in range(1, 10))
'';
# highlighted as python as it should (comment rule)
fromComment = /* python */ ''
from sys import stdin
print(i**2 for i in range(1, 10))
'';
# highlighted as bash as it should ("*Script" rule)
some.dummyScript = ''
from sys import stdin
print(i**2 for i in range(1, 10))
'';
# highlighted weirdly? Should be highlighted as python (comment rule)
another.dummyScript = /* python */ ''
from sys import stdin
print(i**2 for i in range(1, 10))
'';
# highlighted weirdly? Should be highlighted as python ("testScript" rule)
some.testScript = ''
from sys import stdin
print(i**2 for i in range(1, 10))
'';
# highleighted weirdly? Should be highligted as python (comment rule)
another.testScript = /* python */ ''
from sys import stdin
print(i**2 for i in range(1, 10))
'';
} |
I think I saw something like this in my own queries too. IIRC this might have something to do with the injections.combined, which does a little bit more than I want it to. perhaps @the-mikedavis has some insight? |
I think all of these snippets should drop |
abe223c
to
16fafce
Compare
With What's the correct way to set overrides / priorities without combining? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stanzas that are higher in the file will have higher precedence but we will also need to tune the comment injection rule on L5-7. The dummyScript
with a comment case is failing because the stanza on L11 starts matching earlier than the comment stanza (L5). We can add another stanza right next to the comment stanza that starts capturing at the same time, so it will have higher precedence:
; mark arbitary languages with a comment
((((comment) @injection.language) .
(indented_string_expression (string_fragment) @injection.content)))
(binding
(comment) @injection.language
expression: (indented_string_expression (string_fragment) @injection.content))
16fafce
to
e164e03
Compare
fwiw, without |
interpolation like this is difficult since tis not really valid python and instead essentially an injection insice injection. I guess the nixos grammar does actually endup producing multiple syntax nodes here so you would essentially want combining injections within a single TS node (but not globally). That doesn't currently exist in helix however. I think using combined injection does actually represent that more correctly for now. The issues you showed seem odd I don't have time to investigate right now but that looks like an actual highlighting bug. This seems similar to some of the issues I saw (and fixed) in #7621. Jjust to be sure: Are you using the latest master build? |
This rule failed to override other ones because it started its matching later.
e164e03
to
42c3ba8
Compare
I just tested again rebased on master and without removing the combining, It seems to work as expected with the example above in this thread! |
Having scopes for combined injections so that they're limited to some part of the subtree that you select with queries could be useful for other languages (in particular HEEx). That's a feature that we might want to suggest upstream first though since it would benefit any tree-sitter consumer using injections |
I think we would only need to agree on the query syntax tough. The implementation should be entirely possible on our end. |
No description provided.