Walk the AST and extract entities.
(
&self,
node: &Node,
source: &str,
file_path: &str,
entities: &mut Vec<Entity>,
in_class: Option<&str>,
)
| 37 | |
| 38 | /// Walk the AST and extract entities. |
| 39 | fn walk_tree( |
| 40 | &self, |
| 41 | node: &Node, |
| 42 | source: &str, |
| 43 | file_path: &str, |
| 44 | entities: &mut Vec<Entity>, |
| 45 | in_class: Option<&str>, |
| 46 | ) { |
| 47 | match node.kind() { |
| 48 | "function_definition" => { |
| 49 | if let Some(entity) = self.extract_function(node, source, file_path, in_class) { |
| 50 | entities.push(entity); |
| 51 | } |
| 52 | } |
| 53 | "class_definition" => { |
| 54 | if let Some(entity) = self.extract_class(node, source, file_path) { |
| 55 | let class_name = entity.name.clone(); |
| 56 | entities.push(entity); |
| 57 | |
| 58 | // Walk class body for methods |
| 59 | if let Some(body) = node.child_by_field_name("body") { |
| 60 | let mut cursor = body.walk(); |
| 61 | for child in body.children(&mut cursor) { |
| 62 | self.walk_tree(&child, source, file_path, entities, Some(&class_name)); |
| 63 | } |
| 64 | } |
| 65 | return; // Don't recurse into class again below |
| 66 | } |
| 67 | } |
| 68 | // Module-level assignments: `X = 42` or `X: int = 42` |
| 69 | "expression_statement" if in_class.is_none() => { |
| 70 | if let Some(child) = node.child(0) { |
| 71 | if child.kind() == "assignment" || child.kind() == "augmented_assignment" { |
| 72 | if let Some(entity) = self.extract_assignment(&child, source, file_path) { |
| 73 | entities.push(entity); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | "import_statement" | "import_from_statement" => { |
| 79 | if let Some(entity) = self.extract_import(node, source, file_path) { |
| 80 | entities.push(entity); |
| 81 | } |
| 82 | } |
| 83 | "decorated_definition" => { |
| 84 | // Decorated functions/classes — walk into the inner definition |
| 85 | let mut cursor = node.walk(); |
| 86 | for child in node.children(&mut cursor) { |
| 87 | if child.kind() == "function_definition" || child.kind() == "class_definition" { |
| 88 | self.walk_tree(&child, source, file_path, entities, in_class); |
| 89 | } |
| 90 | } |
| 91 | return; // Don't double-recurse |
| 92 | } |
| 93 | _ => {} |
| 94 | } |
| 95 | |
| 96 | // Recurse into children (but not class bodies — handled above) |
no test coverage detected