pub struct QueryMatch<'query, 'tree> { /* private fields */ }Expand description
Wrapper around tree_sitter::QueryMatch
Implementations§
Source§impl<'query, 'tree> QueryMatch<'query, 'tree>
impl<'query, 'tree> QueryMatch<'query, 'tree>
Sourcepub unsafe fn new(
query_match: &QueryMatch<'query, 'tree>,
query: &'query Query,
tree: &'tree Tree,
) -> Self
pub unsafe fn new( query_match: &QueryMatch<'query, 'tree>, query: &'query Query, tree: &'tree Tree, ) -> Self
Wrap a tree-sitter query match.
§Safety
The query match must be from the given tree and query. Additionally, query_match’s
lifetime must be longer than the “lifetime” where any methods may be called on this
structure, despite not being captured in the signature (the structure can outlive
query_match because it stores a raw pointer, but most of its methods dereference, so when
query_match is no longer live they cause UB).
Sourcepub fn iter_captures(&self) -> impl Iterator<Item = QueryCapture<'query, 'tree>>
pub fn iter_captures(&self) -> impl Iterator<Item = QueryCapture<'query, 'tree>>
Iterate all captures in the order they appear.
Sourcepub fn capture(&self, index: usize) -> Option<QueryCapture<'query, 'tree>>
pub fn capture(&self, index: usize) -> Option<QueryCapture<'query, 'tree>>
Get the capture at the given index (order it appears).
Sourcepub fn capture_named(&self, name: &str) -> Option<QueryCapture<'query, 'tree>>
pub fn capture_named(&self, name: &str) -> Option<QueryCapture<'query, 'tree>>
Get the first occurrence of the capture with the given name.
Sourcepub fn captures_named<'a>(
&'a self,
name: &'a str,
) -> impl Iterator<Item = QueryCapture<'query, 'tree>> + 'a
pub fn captures_named<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = QueryCapture<'query, 'tree>> + 'a
Get every occurrence of the captures with the given name.
Sourcepub fn capture_count(&self) -> usize
pub fn capture_count(&self) -> usize
Get the number of captures in this match.
Sourcepub fn pattern_index(&self) -> usize
pub fn pattern_index(&self) -> usize
Get the pattern index of this match.
Sourcepub fn id(&self) -> u32
pub fn id(&self) -> u32
Get the id of this match (honestly I don’t know what this does because it’s not documented)
Sourcepub fn remove(&self)
pub fn remove(&self)
Remove the match (honestly I don’t know what this does because it’s not documented)
Sourcepub fn nodes_for_capture_index(
&self,
capture_index: u32,
) -> impl Iterator<Item = Node<'tree>> + '_
pub fn nodes_for_capture_index( &self, capture_index: u32, ) -> impl Iterator<Item = Node<'tree>> + '_
Get the nodes that were captures by the capture at the given index.
Sourcepub fn as_inner(&self) -> &QueryMatch<'query, 'tree>
pub fn as_inner(&self) -> &QueryMatch<'query, 'tree>
Get the underlying tree_sitter::QueryMatch
Sourcepub fn into_inner(
self,
) -> (*const QueryMatch<'query, 'tree>, &'query Query, &'tree Tree)
pub fn into_inner( self, ) -> (*const QueryMatch<'query, 'tree>, &'query Query, &'tree Tree)
Destruct into the underlying tree_sitter::QueryMatch raw pointer, as well as the query and
tree