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

Method extract_import

codegraph-kernel/src/go.rs:767–810  ·  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

765
766 /// extractImport's Go branch: one import node + ref per import_spec.
767 fn extract_import(&mut self, node: Node<'t>) {
768 let parent = self.top_row();
769 let imports_kind = edge_kind_index("imports").unwrap();
770 let mut handle_spec = |w: &mut Self, spec: Node<'t>| {
771 let lit = (0..spec.named_child_count())
772 .filter_map(|i| spec.named_child(i))
773 .find(|c| c.kind() == "interpreted_string_literal");
774 let Some(lit) = lit else { return };
775 let import_path: String = w
776 .text(lit)
777 .chars()
778 .filter(|c| *c != '\'' && *c != '"')
779 .collect();
780 if import_path.is_empty() {
781 return;
782 }
783 let signature = w.text(spec).trim().to_string();
784 w.create_node(
785 "import",
786 &import_path,
787 spec,
788 Extra { signature: Some(signature), ..Extra::default() },
789 );
790 w.push_ref_at(parent, &import_path, imports_kind, spec);
791 };
792
793 let spec_list = (0..node.named_child_count())
794 .filter_map(|i| node.named_child(i))
795 .find(|c| c.kind() == "import_spec_list");
796 if let Some(list) = spec_list {
797 for spec in list.named_children(&mut list.walk()) {
798 if spec.kind() == "import_spec" {
799 handle_spec(self, spec);
800 }
801 }
802 } else {
803 let spec = (0..node.named_child_count())
804 .filter_map(|i| node.named_child(i))
805 .find(|c| c.kind() == "import_spec");
806 if let Some(spec) = spec {
807 handle_spec(self, spec);
808 }
809 }
810 }
811
812 /// extractCall — Go's generic-tail paths (selector_expression callees).
813 fn extract_call(&mut self, node: Node<'t>) {

Callers 1

visit_nodeMethod · 0.45

Calls 8

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

Tested by

no test coverage detected