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

Method emit_use_binding_refs

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

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

Callers 1

extract_importMethod · 0.80

Calls 6

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

Tested by

no test coverage detected