Walk the AST and extract entities.
(
&self,
node: &Node,
source: &str,
file_path: &str,
entities: &mut Vec<Entity>,
scope: Option<&str>,
in_class: bool,
)
| 53 | |
| 54 | /// Walk the AST and extract entities. |
| 55 | fn walk_tree( |
| 56 | &self, |
| 57 | node: &Node, |
| 58 | source: &str, |
| 59 | file_path: &str, |
| 60 | entities: &mut Vec<Entity>, |
| 61 | scope: Option<&str>, |
| 62 | in_class: bool, |
| 63 | ) { |
| 64 | match node.kind() { |
| 65 | "function_definition" => { |
| 66 | if let Some(entity) = |
| 67 | self.extract_function(node, source, file_path, scope, in_class) |
| 68 | { |
| 69 | entities.push(entity); |
| 70 | } |
| 71 | return; // Don't recurse into function bodies |
| 72 | } |
| 73 | "declaration" => { |
| 74 | // A top-level declaration may contain a function declarator (prototype) |
| 75 | // or a variable/field. We skip plain declarations to avoid noise — |
| 76 | // function_definition already covers implemented functions. |
| 77 | // However, we still recurse below so nested class specifiers etc. are found. |
| 78 | } |
| 79 | "class_specifier" => { |
| 80 | if let Some((entity, raw_name)) = self.extract_class(node, source, file_path, scope) |
| 81 | { |
| 82 | entities.push(entity); |
| 83 | |
| 84 | // Walk class body for methods, nested types. |
| 85 | // Use raw_name (not entity.name) to avoid scope doubling. |
| 86 | let scoped = match scope { |
| 87 | Some(s) => format!("{}::{}", s, raw_name), |
| 88 | None => raw_name, |
| 89 | }; |
| 90 | if let Some(body) = node.child_by_field_name("body") { |
| 91 | let mut cursor = body.walk(); |
| 92 | for child in body.children(&mut cursor) { |
| 93 | self.walk_tree( |
| 94 | &child, |
| 95 | source, |
| 96 | file_path, |
| 97 | entities, |
| 98 | Some(&scoped), |
| 99 | true, |
| 100 | ); |
| 101 | } |
| 102 | } |
| 103 | return; // Don't recurse again below |
| 104 | } |
| 105 | } |
| 106 | "struct_specifier" => { |
| 107 | if let Some((entity, raw_name)) = |
| 108 | self.extract_struct(node, source, file_path, scope) |
| 109 | { |
| 110 | entities.push(entity); |
| 111 | |
| 112 | let scoped = match scope { |
no test coverage detected