Walk the AST and extract entities.
(&self, node: &Node, source: &str, file_path: &str, entities: &mut Vec<Entity>)
| 37 | |
| 38 | /// Walk the AST and extract entities. |
| 39 | fn walk_tree(&self, node: &Node, source: &str, file_path: &str, entities: &mut Vec<Entity>) { |
| 40 | match node.kind() { |
| 41 | "function_declaration" => { |
| 42 | if let Some(entity) = self.extract_function(node, source, file_path) { |
| 43 | entities.push(entity); |
| 44 | } |
| 45 | } |
| 46 | "method_declaration" => { |
| 47 | if let Some(entity) = self.extract_method(node, source, file_path) { |
| 48 | entities.push(entity); |
| 49 | } |
| 50 | } |
| 51 | "type_declaration" => { |
| 52 | // type_declaration contains one or more type_spec children |
| 53 | let mut cursor = node.walk(); |
| 54 | for child in node.children(&mut cursor) { |
| 55 | if child.kind() == "type_spec" { |
| 56 | if let Some(entity) = self.extract_type_spec(&child, source, file_path) { |
| 57 | entities.push(entity); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | "const_declaration" => { |
| 63 | self.extract_const_or_var(node, source, file_path, EntityKind::Const, entities); |
| 64 | } |
| 65 | "var_declaration" => { |
| 66 | self.extract_const_or_var(node, source, file_path, EntityKind::Variable, entities); |
| 67 | } |
| 68 | "import_declaration" => { |
| 69 | if let Some(entity) = self.extract_import(node, source, file_path) { |
| 70 | entities.push(entity); |
| 71 | } |
| 72 | } |
| 73 | _ => {} |
| 74 | } |
| 75 | |
| 76 | // Recurse into children |
| 77 | let mut cursor = node.walk(); |
| 78 | for child in node.children(&mut cursor) { |
| 79 | // Don't recurse into function/method bodies — we only want top-level entities |
| 80 | if child.kind() != "block" { |
| 81 | self.walk_tree(&child, source, file_path, entities); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /// Extract a package-level function declaration. |
| 87 | fn extract_function(&self, node: &Node, source: &str, file_path: &str) -> Option<Entity> { |
no test coverage detected