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

Method emit_use_binding_refs

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

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

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