tree_sitter.rs

 1pub fn count_tree_sitter_errors<'a>(nodes: impl Iterator<Item = tree_sitter::Node<'a>>) -> usize {
 2    let mut total_count: usize = 0;
 3    for node in nodes {
 4        let mut cursor = node.walk();
 5        'node: loop {
 6            let current = cursor.node();
 7            if current.is_error() || current.is_missing() {
 8                total_count += 1;
 9            }
10            if current.has_error() && cursor.goto_first_child() {
11                continue;
12            }
13            if cursor.goto_next_sibling() {
14                continue;
15            }
16            loop {
17                if !cursor.goto_parent() {
18                    break 'node;
19                }
20                if cursor.goto_next_sibling() {
21                    continue;
22                }
23            }
24        }
25    }
26    total_count
27}