-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Allow capturing multiple nodes in textobject queries #1611
Allow capturing multiple nodes in textobject queries #1611
Conversation
5b130a0
to
76081db
Compare
Does this catch grouped alternations? For example the hypothetical following query:
I think perl might have a case where this is needed. |
Only quantifiers after nodes are supported right now, like
[
(line_comment)
(block_comment)
]+ @cap
// line 1
/* line a */
/* line b */
// line 2
/* line c */
// line 3 Running with the tree-sitter cli:
The captures are in separate matches (with one "match" corresponding to matching a pattern uniquely), while I was expecting them to be one single match with multiple captures of
the nodes would have been correctly grouped together. |
Also it seems like [
(line_comment)
]+ @comment works perfectly fine. |
@sudormrfbin I took a quick look and didn't see any issues related to this in the tree-sitter repo. I'm on my phone and about to start my day, can you take the lead on opening an issue there? We could also ping max directly here but it seems like it would be a good one for an issue. Edit: Don't mean to be bossy, I'll handle it you can't get to it. |
Another place this might be useful is in a hypothetical implementation of |
\cc @the-mikedavis regarding the comment queries |
Hmm those query results are stange 🤔 In the grammar line comments are parsed with regular grammar DSL rules but the block comments are done through an external scanner. Maybe there's a difference there with how the queries treat external rules? I know that there are some optimizations so that captures can be emitted eagerly (see here) but I'm not sure that logic is relevant to this case. It's probably worth opening an issue upstream, that seems like a good reproduction case. |
I have opened an upstream issue: tree-sitter/tree-sitter#1639 |
Treesitter captures can contain multiple nodes like so: ``` (line_comment)+ @comment ``` This would match each line in a comment as a separate `@comment` capture when what we actually want is the whole set of contiguous `line_comment` nodes to be captured under the `@comment` capture. This commit enables this behaviour.
76081db
to
645ab4f
Compare
Treesitter captures can contain multiple nodes like so:
This would match each line in a comment as a separate
@comment
capture when what we actually want is the whole set of contiguousline_comment
nodes to be captured under the@comment
capture. This commit enables this behavior. Also required for makingcomment.around
textobject (#1605) work.Note that some cases of multi node capture is not implemented yet, see the commented out test cases for more.
/cc @EpocSquadron