@@ -234,6 +234,7 @@ pub struct TextObjectQuery {
234 pub query: Query,
234 pub query: Query,
237pub enum CapturedNode<'a> {
238pub enum CapturedNode<'a> {
238 Single(Node<'a>),
239 Single(Node<'a>),
239 /// Guaranteed to be not empty
240 /// Guaranteed to be not empty
@@ -268,12 +269,12 @@ impl TextObjectQuery {
268 /// and support for this is partial and could use improvement.
269 /// and support for this is partial and could use improvement.
270 /// ```query
271 /// ```query
272 /// (comment)+ @capture
272 /// (comment)+ @capture
274− /// ;; unsupported:
274+ /// ; OR
276− /// (comment)+
276+ /// (comment)*
277 /// (function)
278 /// (function)
278 /// ) @capture
279 /// ) @capture
@@ -299,28 +300,29 @@ impl TextObjectQuery {
299 let capture_idx = capture_names
300 let capture_idx = capture_names
301 .find_map(|cap| self.query.capture_index_for_name(cap))?;
302 .find_map(|cap| self.query.capture_index_for_name(cap))?;
302− let captures = cursor.matches(&self.query, node, RopeProvider(slice));
305+ .captures(&self.query, node, RopeProvider(slice))
303−
306+ .filter_map(move |(mat, _)| {
304− let nodes = captures.flat_map(move |mat| {
307+ let nodes: Vec<_> = mat
305− let captures = mat.captures.iter().filter(move |c| c.index == capture_idx);
311+ if x.index == capture_idx {
306− let nodes = captures.map(|c| c.node);
312+ Some(x.node)
307− let pattern_idx = mat.pattern_index;
313+ } else {
308− let quantifier = self.query.capture_quantifiers(pattern_idx)[capture_idx as usize];
314+ None
310− let iter: Box<dyn Iterator<Item = CapturedNode>> = match quantifier {
316+ })
311− CaptureQuantifier::OneOrMore | CaptureQuantifier::ZeroOrMore => {
312− let nodes: Vec<Node> = nodes.collect();
317+ .collect();
313− if nodes.is_empty() {
319+ if nodes.len() > 1 {
314− Box::new(std::iter::empty())
316− Box::new(std::iter::once(CapturedNode::Grouped(nodes)))
320+ Some(CapturedNode::Grouped(nodes))
322+ nodes.into_iter().map(CapturedNode::Single).next()
319− _ => Box::new(nodes.map(CapturedNode::Single)),
324 Some(nodes)
326 Some(nodes)
@@ -1122,8 +1124,8 @@ pub(crate) fn generate_edits(
1122use std::sync::atomic::{AtomicUsize, Ordering};
1124use std::sync::atomic::{AtomicUsize, Ordering};
1123use std::{iter, mem, ops, str, usize};
1125use std::{iter, mem, ops, str, usize};
1124use tree_sitter::{
1126use tree_sitter::{
1125− CaptureQuantifier, Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor,
1127+ Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
1126− QueryError, QueryMatch, Range, TextProvider, Tree,
1128+ QueryMatch, Range, TextProvider, Tree,
1129const CANCELLATION_CHECK_INTERVAL: usize = 100;
1131const CANCELLATION_CHECK_INTERVAL: usize = 100;