Recursively find the first node of the given kind.
(node: tree_sitter::Node<'a>, kind: &str)
| 17 | |
| 18 | /// Recursively find the first node of the given kind. |
| 19 | fn find_first_kind<'a>(node: tree_sitter::Node<'a>, kind: &str) -> Option<tree_sitter::Node<'a>> { |
| 20 | if node.kind() == kind { |
| 21 | return Some(node); |
| 22 | } |
| 23 | let mut cursor = node.walk(); |
| 24 | if cursor.goto_first_child() { |
| 25 | loop { |
| 26 | if let Some(found) = find_first_kind(cursor.node(), kind) { |
| 27 | return Some(found); |
| 28 | } |
| 29 | if !cursor.goto_next_sibling() { |
| 30 | break; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | None |
| 35 | } |
| 36 | |
| 37 | // ── Branch counting ───────────────────────────────────────────────────────── |
| 38 |
no test coverage detected