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

Method emit_use_binding_refs

codegraph-kernel/src/rustlang.rs:822–882  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

820 /// ref per binding; `Path as Alias` links the source path; leaves that are
821 /// only `self`/`super`/`crate`/`*` are skipped.
822 fn emit_use_binding_refs(&mut self, node: Node<'t>, from_row: u32) {
823 let mut paths: Vec<(String, Node)> = Vec::new();
824 fn join(prefix: &str, seg: &str) -> String {
825 if prefix.is_empty() { seg.to_string() } else { format!("{prefix}::{seg}") }
826 }
827 fn collect<'t>(w: &Walker<'t>, n: Node<'t>, prefix: &str, paths: &mut Vec<(String, Node<'t>)>) {
828 stack_guard!();
829 match n.kind() {
830 "identifier" => paths.push((join(prefix, w.text(n)), n)),
831 "scoped_identifier" => {
832 let full = w.text(n).trim();
833 paths.push((
834 if prefix.is_empty() { full.to_string() } else { format!("{prefix}::{full}") },
835 n,
836 ));
837 }
838 "scoped_use_list" => {
839 let seg = n
840 .child_by_field_name("path")
841 .map(|p| w.text(p).trim().to_string())
842 .unwrap_or_default();
843 let new_prefix = if seg.is_empty() { prefix.to_string() } else { join(prefix, &seg) };
844 let list = n.child_by_field_name("list").or_else(|| {
845 (0..n.named_child_count())
846 .filter_map(|i| n.named_child(i))
847 .find(|c| c.kind() == "use_list")
848 });
849 if let Some(list) = list {
850 collect(w, list, &new_prefix, paths);
851 }
852 }
853 "use_list" => {
854 for i in 0..n.named_child_count() {
855 if let Some(c) = n.named_child(i) {
856 collect(w, c, prefix, paths);
857 }
858 }
859 }
860 "use_as_clause" => {
861 let p = n.child_by_field_name("path").or_else(|| n.named_child(0));
862 if let Some(p) = p {
863 collect(w, p, prefix, paths);
864 }
865 }
866 _ => {} // visibility_modifier, use_wildcard, bare crate/self/super
867 }
868 }
869 for i in 0..node.named_child_count() {
870 if let Some(c) = node.named_child(i) {
871 collect(self, c, "", &mut paths);
872 }
873 }
874 let imports_kind = edge_kind_index("imports").unwrap();
875 for (text, n) in paths {
876 let leaf = text.rsplit("::").next().unwrap_or("");
877 if leaf.is_empty() || matches!(leaf, "self" | "super" | "crate" | "*") {
878 continue;
879 }

Callers 1

extract_importMethod · 0.80

Calls 5

edge_kind_indexFunction · 0.85
nextMethod · 0.80
unwrapMethod · 0.60
collectFunction · 0.50
push_ref_atMethod · 0.45

Tested by

no test coverage detected