-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
tree-sitter-grammars: Enable grammar testing #391520
base: staging
Are you sure you want to change the base?
tree-sitter-grammars: Enable grammar testing #391520
Conversation
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.
I'm surprised the emacs plug-in doesn't seem to do the same as nvim-treesitter
(separately locked grammars, specific to the plug-in).
Should we worry about reporting a grammar as broken "just" because some its tests aren't passing, if it builds and actually parses its inputs? I'm kind of surprised at the number of grammars which turned up broken = true
here.
@@ -76,6 +76,7 @@ let | |||
src = grammar.src or (fetchGrammar grammar); | |||
location = grammar.location or null; | |||
generate = grammar.generate or false; | |||
isBroken = grammar ? isBroken && grammar.isBroken; |
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.
isBroken = grammar ? isBroken && grammar.isBroken; | |
isBroken = grammar ? isBroken or false; |
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.
isBroken
is always false
indeed.
isBroken = grammar ? isBroken;
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.
Your suggestion raises an error. I am not sure why...
nix-repl> attr = {a=true; b=false;}
nix-repl> (attr ? c) or false
error: undefined variable 'or'
at «string»:1:1:
1| (attr ? c) or false
| ^
nix-repl> attr.a or false
true
Maybe instead: broken = grammar.broken or false
.
@@ -58,4 +65,9 @@ stdenv.mkDerivation ({ | |||
fi | |||
runHook postInstall | |||
''; | |||
|
|||
meta = { | |||
broken = isBroken; |
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.
Might as well rename it to broken
and inherit
it here IMO.
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.
isBroken
is always false (since it is generated by the update script), the name indicates that is flagged as broken.
I don't mind changing it to broken
.
The reason behind this choice is to avoid updating all the JSON files without a new and unnecessary attribute.
|
||
|
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.
Belongs in a different commit.
|
||
if not check_grammar(data): | ||
# Test the grammar with Tree-sitter and set the isBroken flag accordingly | ||
data['isBroken'] = not check_grammar(data) |
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.
Related to my earlier comment about isBroken
/broken
naming.
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.
amended.
...cations/editors/emacs/elisp-packages/manual-packages/tree-sitter-langs/default-grammars.json
Show resolved
Hide resolved
...plications/editors/emacs/elisp-packages/manual-packages/tree-sitter-langs/update-defaults.py
Outdated
Show resolved
Hide resolved
...plications/editors/emacs/elisp-packages/manual-packages/tree-sitter-langs/update-defaults.py
Show resolved
Hide resolved
|
Honestly, I can't say. That's why it is important to have feedback. What I can say (working on this PR for almost a year now), is that the recent bump from tree-sitter 0.24 to 0.25 has increased the number of broken grammar. The lack of testing is probably at cause here. |
Very much appreciate the effort to add some testing. |
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.
Looks fine aside from what had already been said by ambroisie.
if not check_grammar(data): | ||
# Test the grammar with Tree-sitter and set the isBroken flag accordingly | ||
data['broken'] = not check_grammar(data) |
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.
I think this could just use a variable instead of having to run the check twice.
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.
Wow, good catch. Thank you.
a81917f
to
1439f9f
Compare
We should keep the commit history clean- can we squash the fixups? |
I split everything into atomics commit for the review. Indeed, the goal is to merge, but should I do it know? Please be mindful of my time, git manipulations like that take time and can be error-prone. |
Thank you for the link; it was very informative. Sorry, I meant "now" (not "know") in my original message. I was asked to split everything into atomic commits for the review and then rebase once we agree on all the changes (discussion). At least, that's how I understood it. I will rebase, but I want to avoid unnecessary git manipulations unless a commit needs to be split because it doesn't meet the first commit convention (each commit must be a logical unit, though logical unit is likely subject to interpretation). |
1439f9f
to
0cf6ba1
Compare
It is done! Please let me know if it works for you. |
2de8950
to
0044ec1
Compare
Appreciate organizing the commits more, makes it easier to step through changes. |
0044ec1
to
23d6584
Compare
Hi, I just:
Please let me know if you see something else. |
a58f0db
to
e508012
Compare
One wrench to throw in here, I don't know if some of the changes need to target staging.. I think we've had |
I think that you are right, at least it was the case for this recent update of tree-sitter (#389796). If I understand correctly, to achieve that, I need to update the target branch in GitHub and rebase on top of staging? |
@adfaure you need to follow the contributing guide about how to retarget an MR, to avoid mass-pinging people. |
e508012
to
afdbc8a
Compare
afdbc8a
to
868a440
Compare
Ok It's done, I have followed the guide. I hope it didn't trigger too many pings. Sorry, if it did. |
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.
Looking good, just one small nit.
checkPhase = '' | ||
runHook preCheck | ||
|
||
# HOME is needed because tree-sitter needs a writable home folder |
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.
Comment should go with writableTmpDirAsHomeHook
.
97ca3ae
to
0ee981b
Compare
0ee981b
to
50e28d7
Compare
Description of changes
Context
While working on #320783 with @fricklerhandwerk. We used
tree-sitter-grammars
to build Python bindings, we explored ways to test these grammars. We found that the best approach is to use Tree-sitter's dedicated testing framework (documentation).This PR introduces a check phase using
tree-sitter test
.Changes
Activate Grammar Testing
Adds a test phase and an
isBroken
attribute.Runs the tests during the update phase and sets the
isBroken
attribute if the tests fail.Update the Emacs Script
Emacs has an automated mechanism for updating grammars. This script is updated to use the
isBroken
flag.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.