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

Method emit_use_binding_refs

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

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

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