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

Method walk_tree

atomic-semantic/src/parser.rs:545–645  ·  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

543
544 /// Walk the AST and extract entities
545 fn walk_tree(
546 &self,
547 node: &Node,
548 source: &str,
549 file_path: &str,
550 entities: &mut Vec<Entity>,
551 in_export: bool,
552 ) {
553 // Check if this node is an export statement
554 let is_export = node.kind() == "export_statement";
555 let child_in_export = in_export || is_export;
556
557 match node.kind() {
558 "import_statement" | "export_statement" => {
559 if let Some(module) = node.child_by_field_name("source") {
560 if let Some(text) = self.node_text(&module, source) {
561 entities.push(
562 Entity::new(
563 text.trim_matches(['\'', '"']),
564 EntityKind::Import,
565 file_path,
566 node.start_position().row as u32 + 1,
567 node.end_position().row as u32 + 1,
568 )
569 .with_signature(self.node_text(node, source).unwrap_or_default()),
570 );
571 }
572 }
573 }
574
575 // Function declarations
576 "function_declaration" => {
577 if let Some(entity) =
578 self.extract_function(node, source, file_path, child_in_export)
579 {
580 entities.push(entity);
581 }
582 }
583
584 // Arrow functions assigned to variables (const foo = () => {})
585 "lexical_declaration" | "variable_declaration" => {
586 entities.extend(self.extract_variable_declarations(
587 node,
588 source,
589 file_path,
590 child_in_export,
591 ));
592 }
593
594 // Class declarations
595 "class_declaration" => {
596 if let Some(entity) = self.extract_class(node, source, file_path, child_in_export) {
597 entities.push(entity);
598 }
599 // Also extract methods from the class
600 self.extract_class_members(node, source, file_path, entities);
601 }
602

Callers 1

extractMethod · 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