-
-
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
Fix crash for overlapping injections #7621
Fix crash for overlapping injections #7621
Conversation
89596f9
to
209814f
Compare
209814f
to
11ac7b9
Compare
My laptop currently doesnt have internet so I can't test this pr out but would this also fix #3816 |
I haven't tested this and wknt get a chance fir a whike but assuming your comments there are accurate then this would ended fix that bug too. You werent too far off there with your fix. This essentially does the same thing as deduplication but also handles cases where ranges overlap (instead of being exactly the same) and handles all overlaps (not just thise of a singke combined injection). I just wasnt aware if that issue/your comments there :D If you could confirm once you habe time to test we can links that issue to this PR |
I suspect there are more issues that are fixed by this @the-mikedavis mentioned he wanted to test if this fixes some issues |
I can confirm this fixes #3816 and fixes nix-community/tree-sitter-nix#39 which was the same issue and it also fixes #7578 |
Thanks for going trough all those issues! That's more than I expected |
In the past we used two separate queries for combined and normal injections. There was no real reason for this (except historical/slightly easier implementation). Instead, we now use a single query and simply check if an injection corresponds to a combined injection or not.
11ac7b9
to
dc4173c
Compare
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.
Took me a bit of time to properly review, but it's great that a single fix closes so many issues! Thanks @gabydd for combing through the issue tracker and retesting!
Fixes #7434
fixes #3816
fixes nix-community/tree-sitter-nix#39
fixes #7578
fixes #3283
fixes #7615
The crash was caused by creating multiple overlapping injections (one for
bash
and another one for the shebang). Having two overlapping injections in the same layer doesn't make much sense. Therefore, I added a simple check that skips any injection that intersects with a previous one.This works because queries are visited in ascending order (start never decreases). However, we had two queries for injections: one for combined injections and normal injections. That meant that overlaps between combined and normal injections weren't caught which could lead to similar bugs.
To fix this I would have to sort injections which would be inefficient for large files with many injections Luckily it was fairly easy to merge the queries for combined and injection queries. This is also a small optimization as it means we run one less query (on the entire file) during parsing.
Marked for next since this crash is a regression (its technically an existing bub but normally we never have overlapping injections)