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