MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / walk_tree

Method walk_tree

atomic-semantic/src/parsers/rust.rs:45–144  ·  view source on GitHub ↗

Walk the AST and extract entities.

(
        &self,
        node: &Node,
        source: &str,
        file_path: &str,
        entities: &mut Vec<Entity>,
        in_impl: Option<&str>,
    )

Source from the content-addressed store, hash-verified

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) {

Callers 1

extractMethod · 0.45

Calls 15

extract_traitMethod · 0.80
walkMethod · 0.80
childrenMethod · 0.80
extract_impl_nameMethod · 0.80
build_impl_signatureMethod · 0.80
with_signatureMethod · 0.80
extract_constMethod · 0.80
extract_staticMethod · 0.80
extract_modMethod · 0.80
extract_useMethod · 0.80
kindMethod · 0.45
extract_functionMethod · 0.45

Tested by

no test coverage detected