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

Method extract_import

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

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