@@ -234,6 +234,7 @@ pub struct TextObjectQuery {
234234 pub query: Query,
235235}
236236
237+#[derive(Debug)]
237238pub enum CapturedNode<'a> {
238239 Single(Node<'a>),
239240 /// Guaranteed to be not empty
@@ -268,12 +269,12 @@ impl TextObjectQuery {
268269 /// and support for this is partial and could use improvement.
269270 ///
270271 /// ```query
271− /// ;; supported:
272272 /// (comment)+ @capture
273273 ///
274− /// ;; unsupported:
274+ /// ; OR
275275 /// (
276− /// (comment)+
276+ /// (comment)*
277+ /// .
277278 /// (function)
278279 /// ) @capture
279280 /// ```
@@ -299,28 +300,29 @@ impl TextObjectQuery {
299300 let capture_idx = capture_names
300301 .iter()
301302 .find_map(|cap| self.query.capture_index_for_name(cap))?;
302− let captures = cursor.matches(&self.query, node, RopeProvider(slice));
303−
304− let nodes = captures.flat_map(move |mat| {
305− let captures = mat.captures.iter().filter(move |c| c.index == capture_idx);
306− let nodes = captures.map(|c| c.node);
307− let pattern_idx = mat.pattern_index;
308− let quantifier = self.query.capture_quantifiers(pattern_idx)[capture_idx as usize];
309−
310− let iter: Box<dyn Iterator<Item = CapturedNode>> = match quantifier {
311− CaptureQuantifier::OneOrMore | CaptureQuantifier::ZeroOrMore => {
312− let nodes: Vec<Node> = nodes.collect();
313− if nodes.is_empty() {
314− Box::new(std::iter::empty())
315− } else {
316− Box::new(std::iter::once(CapturedNode::Grouped(nodes)))
317− }
303+
304+ let nodes = cursor
305+ .captures(&self.query, node, RopeProvider(slice))
306+ .filter_map(move |(mat, _)| {
307+ let nodes: Vec<_> = mat
308+ .captures
309+ .iter()
310+ .filter_map(|x| {
311+ if x.index == capture_idx {
312+ Some(x.node)
313+ } else {
314+ None
315+ }
316+ })
317+ .collect();
318+
319+ if nodes.len() > 1 {
320+ Some(CapturedNode::Grouped(nodes))
321+ } else {
322+ nodes.into_iter().map(CapturedNode::Single).next()
318323 }
319− _ => Box::new(nodes.map(CapturedNode::Single)),
320− };
324+ });
321325
322− iter
323− });
324326 Some(nodes)
325327 }
326328}
@@ -1122,8 +1124,8 @@ pub(crate) fn generate_edits(
11221124use std::sync::atomic::{AtomicUsize, Ordering};
11231125use std::{iter, mem, ops, str, usize};
11241126use tree_sitter::{
1125− CaptureQuantifier, Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor,
1126− QueryError, QueryMatch, Range, TextProvider, Tree,
1127+ Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
1128+ QueryMatch, Range, TextProvider, Tree,
11271129};
11281130
11291131const CANCELLATION_CHECK_INTERVAL: usize = 100;