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

Method walk_tree

atomic-semantic/src/parser.rs:573–673  ·  view source on GitHub ↗

Walk the AST and extract entities

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

Source from the content-addressed store, hash-verified

571
572 /// Walk the AST and extract entities
573 fn walk_tree(
574 &self,
575 node: &Node,
576 source: &str,
577 file_path: &str,
578 entities: &mut Vec<Entity>,
579 in_export: bool,
580 ) {
581 // Check if this node is an export statement
582 let is_export = node.kind() == "export_statement";
583 let child_in_export = in_export || is_export;
584
585 match node.kind() {
586 "import_statement" | "export_statement" => {
587 if let Some(module) = node.child_by_field_name("source") {
588 if let Some(text) = self.node_text(&module, source) {
589 entities.push(
590 Entity::new(
591 text.trim_matches(['\'', '"']),
592 EntityKind::Import,
593 file_path,
594 node.start_position().row as u32 + 1,
595 node.end_position().row as u32 + 1,
596 )
597 .with_signature(self.node_text(node, source).unwrap_or_default()),
598 );
599 }
600 }
601 }
602
603 // Function declarations
604 "function_declaration" => {
605 if let Some(entity) =
606 self.extract_function(node, source, file_path, child_in_export)
607 {
608 entities.push(entity);
609 }
610 }
611
612 // Arrow functions assigned to variables (const foo = () => {})
613 "lexical_declaration" | "variable_declaration" => {
614 entities.extend(self.extract_variable_declarations(
615 node,
616 source,
617 file_path,
618 child_in_export,
619 ));
620 }
621
622 // Class declarations
623 "class_declaration" => {
624 if let Some(entity) = self.extract_class(node, source, file_path, child_in_export) {
625 entities.push(entity);
626 }
627 // Also extract methods from the class
628 self.extract_class_members(node, source, file_path, entities);
629 }
630

Callers 1

extract_from_treeMethod · 0.45

Calls 14

extendMethod · 0.80
extract_class_membersMethod · 0.80
extract_moduleMethod · 0.80
child_countMethod · 0.80
kindMethod · 0.45
node_textMethod · 0.45
pushMethod · 0.45
with_signatureMethod · 0.45
extract_functionMethod · 0.45
extract_classMethod · 0.45
extract_interfaceMethod · 0.45

Tested by

no test coverage detected