rust: Change QueryCursor::captures to expose the full match
This commit is contained in:
parent
3e040b8951
commit
9872a083b7
7 changed files with 172 additions and 104 deletions
|
|
@ -34,12 +34,15 @@ pub fn query_files_at_paths(
|
|||
let tree = parser.parse(&source_code, None).unwrap();
|
||||
|
||||
if ordered_captures {
|
||||
for (pattern_index, capture) in query_cursor.captures(&query, tree.root_node(), text_callback) {
|
||||
for (mat, capture_index) in
|
||||
query_cursor.captures(&query, tree.root_node(), text_callback)
|
||||
{
|
||||
let capture = mat.captures[capture_index];
|
||||
writeln!(
|
||||
&mut stdout,
|
||||
" pattern: {}, capture: {}, row: {}, text: {:?}",
|
||||
pattern_index,
|
||||
&query.capture_names()[capture.index],
|
||||
mat.pattern_index,
|
||||
&query.capture_names()[capture.index as usize],
|
||||
capture.node.start_position().row,
|
||||
capture.node.utf8_text(&source_code).unwrap_or("")
|
||||
)?;
|
||||
|
|
@ -47,11 +50,11 @@ pub fn query_files_at_paths(
|
|||
} else {
|
||||
for m in query_cursor.matches(&query, tree.root_node(), text_callback) {
|
||||
writeln!(&mut stdout, " pattern: {}", m.pattern_index)?;
|
||||
for capture in m.captures() {
|
||||
for capture in m.captures {
|
||||
writeln!(
|
||||
&mut stdout,
|
||||
" capture: {}, row: {}, text: {:?}",
|
||||
&query.capture_names()[capture.index],
|
||||
&query.capture_names()[capture.index as usize],
|
||||
capture.node.start_position().row,
|
||||
capture.node.utf8_text(&source_code).unwrap_or("")
|
||||
)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue