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

Method extract_import

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

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

Callers 1

visit_nodeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected