Replies: 3 comments 1 reply
-
This is very similar, but not quite the same: #2070 I'm trying to use the advice in there (using . and _) to modify my query, but I'm clearly not doing something right:
still produces [b, c, d] Various permutations either result in nothing being found or the same results. Not sure what I'm doing wrong here. |
Beta Was this translation helpful? Give feedback.
-
I've partially figured out my issue - it appears the trick in #2070 only works if your inner query has enough layers. So the reason it's not working for me is I'm directly trying to match attribute, and not the thing that might contain the attribute. Since an attribute could be the child of any number of layers, i'm trying to avoid explicitly putting every permutation that could contain an attribute. Still trying to work on that, but I'm getting there and will post a solution when i fully get it. |
Beta Was this translation helpful? Give feedback.
-
It looks like the basic issue I'm having is that the attribute tag is nested with other tags, and as far as tree-sitter is concerned, the node in question is a sibling, rather than a descendant. This: <div data-test='a'>
<div data-test='b'></div>
<div data-test='c'>
<div data-test='d'></div>
</div>
</div> Produces:
So even though the divs are nested, the way tree-sitter represents them is not nested. I would have assumed that something like I can't figure out how to work around this. |
Beta Was this translation helpful? Give feedback.
-
I'm currently using
tree-sitter-heex
as my language. This is my query:When I run the above query over these contents:
it correctly pulls out
['a', 'b', 'c', 'd']
However, my ultimate goal is to maintain their relative positions, i.e.:
Since I don't think there's a way in tree-sitter to generate that directly, I'm first getting the flat list, then re-running the query on that node:
The problem with this approach is
aDescendantMatches
should includeb
andc
, but notd
, and I'm not sure how to modify the query appropriately.If there's a better way to build my map than something like this, feel free to show how to do that instead.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions