Walk the AST and extract entities.
(
&self,
node: &Node,
source: &str,
file_path: &str,
entities: &mut Vec<Entity>,
in_impl: Option<&str>,
)
| 43 | |
| 44 | /// Walk the AST and extract entities. |
| 45 | fn walk_tree( |
| 46 | &self, |
| 47 | node: &Node, |
| 48 | source: &str, |
| 49 | file_path: &str, |
| 50 | entities: &mut Vec<Entity>, |
| 51 | in_impl: Option<&str>, |
| 52 | ) { |
| 53 | match node.kind() { |
| 54 | "function_item" => { |
| 55 | if let Some(entity) = self.extract_function(node, source, file_path, in_impl) { |
| 56 | entities.push(entity); |
| 57 | } |
| 58 | } |
| 59 | "struct_item" => { |
| 60 | if let Some(entity) = self.extract_struct(node, source, file_path) { |
| 61 | entities.push(entity); |
| 62 | } |
| 63 | } |
| 64 | "enum_item" => { |
| 65 | if let Some(entity) = self.extract_enum(node, source, file_path) { |
| 66 | entities.push(entity); |
| 67 | } |
| 68 | } |
| 69 | "trait_item" => { |
| 70 | if let Some(entity) = self.extract_trait(node, source, file_path) { |
| 71 | let trait_name = entity.name.clone(); |
| 72 | entities.push(entity); |
| 73 | |
| 74 | // Walk trait body for method signatures |
| 75 | if let Some(body) = node.child_by_field_name("body") { |
| 76 | let mut cursor = body.walk(); |
| 77 | for child in body.children(&mut cursor) { |
| 78 | self.walk_tree(&child, source, file_path, entities, Some(&trait_name)); |
| 79 | } |
| 80 | } |
| 81 | return; |
| 82 | } |
| 83 | } |
| 84 | "impl_item" => { |
| 85 | let impl_name = self.extract_impl_name(node, source); |
| 86 | if let Some(ref name) = impl_name { |
| 87 | // Create an entity for the impl block itself |
| 88 | let line = node.start_position().row as u32 + 1; |
| 89 | let end_line = node.end_position().row as u32 + 1; |
| 90 | let sig = self.build_impl_signature(node, source); |
| 91 | |
| 92 | let mut entity = |
| 93 | Entity::new(name.clone(), EntityKind::Module, file_path, line, end_line); |
| 94 | if let Some(s) = sig { |
| 95 | entity = entity.with_signature(s); |
| 96 | } |
| 97 | entities.push(entity); |
| 98 | |
| 99 | // Walk impl body for methods |
| 100 | if let Some(body) = node.child_by_field_name("body") { |
| 101 | let mut cursor = body.walk(); |
| 102 | for child in body.children(&mut cursor) { |
no test coverage detected