emitRustUseBindingRefs (tree-sitter.ts:3451) — one FULL-path `imports` ref per binding; `Path as Alias` links the source path; leaves that are only `self`/`super`/`crate`/`*` are skipped.
(&mut self, node: Node<'t>, from_row: u32)
| 712 | /// ref per binding; `Path as Alias` links the source path; leaves that are |
| 713 | /// only `self`/`super`/`crate`/`*` are skipped. |
| 714 | fn emit_use_binding_refs(&mut self, node: Node<'t>, from_row: u32) { |
| 715 | let mut paths: Vec<(String, Node)> = Vec::new(); |
| 716 | fn join(prefix: &str, seg: &str) -> String { |
| 717 | if prefix.is_empty() { seg.to_string() } else { format!("{prefix}::{seg}") } |
| 718 | } |
| 719 | fn collect<'t>(w: &Walker<'t>, n: Node<'t>, prefix: &str, paths: &mut Vec<(String, Node<'t>)>) { |
| 720 | match n.kind() { |
| 721 | "identifier" => paths.push((join(prefix, w.text(n)), n)), |
| 722 | "scoped_identifier" => { |
| 723 | let full = w.text(n).trim(); |
| 724 | paths.push(( |
| 725 | if prefix.is_empty() { full.to_string() } else { format!("{prefix}::{full}") }, |
| 726 | n, |
| 727 | )); |
| 728 | } |
| 729 | "scoped_use_list" => { |
| 730 | let seg = n |
| 731 | .child_by_field_name("path") |
| 732 | .map(|p| w.text(p).trim().to_string()) |
| 733 | .unwrap_or_default(); |
| 734 | let new_prefix = if seg.is_empty() { prefix.to_string() } else { join(prefix, &seg) }; |
| 735 | let list = n.child_by_field_name("list").or_else(|| { |
| 736 | (0..n.named_child_count()) |
| 737 | .filter_map(|i| n.named_child(i)) |
| 738 | .find(|c| c.kind() == "use_list") |
| 739 | }); |
| 740 | if let Some(list) = list { |
| 741 | collect(w, list, &new_prefix, paths); |
| 742 | } |
| 743 | } |
| 744 | "use_list" => { |
| 745 | for i in 0..n.named_child_count() { |
| 746 | if let Some(c) = n.named_child(i) { |
| 747 | collect(w, c, prefix, paths); |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | "use_as_clause" => { |
| 752 | let p = n.child_by_field_name("path").or_else(|| n.named_child(0)); |
| 753 | if let Some(p) = p { |
| 754 | collect(w, p, prefix, paths); |
| 755 | } |
| 756 | } |
| 757 | _ => {} // visibility_modifier, use_wildcard, bare crate/self/super |
| 758 | } |
| 759 | } |
| 760 | for i in 0..node.named_child_count() { |
| 761 | if let Some(c) = node.named_child(i) { |
| 762 | collect(self, c, "", &mut paths); |
| 763 | } |
| 764 | } |
| 765 | let imports_kind = edge_kind_index("imports").unwrap(); |
| 766 | for (text, n) in paths { |
| 767 | let leaf = text.rsplit("::").next().unwrap_or(""); |
| 768 | if leaf.is_empty() || matches!(leaf, "self" | "super" | "crate" | "*") { |
| 769 | continue; |
| 770 | } |
| 771 | self.push_ref_at(from_row, &text, imports_kind, n); |
no test coverage detected