MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_import

Method extract_import

codegraph-kernel/src/go.rs:675–720  ·  view source on GitHub ↗

extractImport's Go branch: one import node + ref per import_spec.

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

673
674 /// extractImport's Go branch: one import node + ref per import_spec.
675 fn extract_import(&mut self, node: Node<'t>) {
676 let parent = self.top_row();
677 let imports_kind = edge_kind_index("imports").unwrap();
678 let mut handle_spec = |w: &mut Self, spec: Node<'t>| {
679 let lit = (0..spec.named_child_count())
680 .filter_map(|i| spec.named_child(i))
681 .find(|c| c.kind() == "interpreted_string_literal");
682 let Some(lit) = lit else { return };
683 let import_path: String = w
684 .text(lit)
685 .chars()
686 .filter(|c| *c != '\'' && *c != '"')
687 .collect();
688 if import_path.is_empty() {
689 return;
690 }
691 let signature = w.text(spec).trim().to_string();
692 w.create_node(
693 "import",
694 &import_path,
695 spec,
696 Extra { signature: Some(signature), ..Extra::default() },
697 );
698 w.push_ref_at(parent, &import_path, imports_kind, spec);
699 };
700
701 let spec_list = (0..node.named_child_count())
702 .filter_map(|i| node.named_child(i))
703 .find(|c| c.kind() == "import_spec_list");
704 if let Some(list) = spec_list {
705 for i in 0..list.named_child_count() {
706 if let Some(spec) = list.named_child(i) {
707 if spec.kind() == "import_spec" {
708 handle_spec(self, spec);
709 }
710 }
711 }
712 } else {
713 let spec = (0..node.named_child_count())
714 .filter_map(|i| node.named_child(i))
715 .find(|c| c.kind() == "import_spec");
716 if let Some(spec) = spec {
717 handle_spec(self, spec);
718 }
719 }
720 }
721
722 /// extractCall — Go's generic-tail paths (selector_expression callees).
723 fn extract_call(&mut self, node: Node<'t>) {

Callers 1

visit_nodeMethod · 0.45

Calls 7

edge_kind_indexFunction · 0.85
unwrapMethod · 0.60
top_rowMethod · 0.45
collectMethod · 0.45
textMethod · 0.45
create_nodeMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected