pkgcheck/bash: sort captures by line and column#778
Conversation
|
LGTM but please link to the bug in the commit message. |
a7e2b9c to
957d98c
Compare
|
I haven't checked all the call sites for bash.cmd_query.captures(...).get("call", ())these uses should not be negatively impacted by this change. An alternative (and more conservative) approach is to create parallel variables like EDIT: I also don't have any numbers for how much overhead the node sorting adds. |
957d98c to
ee4f9bd
Compare
|
It sounds bike-sheddy, but I'd drop the Either way, that's not a simple thing you ran down ;) |
Sure, I can do that.
Was a fun detective hunt ;) |
It has been observed that the order of nodes returned by tree-sitter's QueryCursor is not necessarily in order wrt line and column in the source, but it appears that some of pkgcheck's usage of tree-sitter assumes that captured nodes are returned in order. There doesn't appear to any features in QueryCursor (or other places) that allows one to specify that returned nodes should be ordered in a specific way, so instead we introduce a decorator on QueryCursor that takes dict of captured nodes and sorts each list of nodes by line and column. Fixes: #702 Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
ee4f9bd to
886b352
Compare
|
Ignore the 'unmerged' message; this is merged- thanks. For future commits, please setup gpg signing- in this case I added my own 'signed-off', so I signed the commit (your authorship is obviously preserved). That resolved the hard requirement that all commits must be gpg signed, but in the future, it's simpler if you have it enabled. Sans that- I noticed this particular primitive has no unit tests. I'm not sure they would've flushed this out, but do you mind taking a look at adding some basic test assertions? Your fix has no coverage, but what caught my eye is the various utility queries- Downstream tests likely verify this, but if treesitter changes something, it's preferable we catch it at this level, rather than doing the "wtf?" detective thing you had to do ;) Thanks! |
|
Thanks for merging, I've set up gpg signing now. I can look at adding some unit tests to the bash module. |
It has been observed that the order of nodes returned by tree-sitter's QueryCursor is not necessarily in order wrt line and column in the source, but it appears that some of pkgcheck's usage of tree-sitter assumes that captured nodes are returned in order.
There doesn't appear to any features in QueryCursor (or other places) that allows one to specify that returned nodes should be ordered in a specific way, so instead we introduce a decorator on QueryCursor that takes dict of captured nodes and sorts each list of nodes by line and column.