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

Method flush_value_refs

codegraph-kernel/src/ruby.rs:1000–1109  ·  view source on GitHub ↗
(&mut self, root: Node<'t>)

Source from the content-addressed store, hash-verified

998 // --- value references (crib of python.rs — same traversal, same cases) ------
999
1000 fn flush_value_refs(&mut self, root: Node<'t>) {
1001 let scopes = std::mem::take(&mut self.value_scopes);
1002 let mut targets = std::mem::take(&mut self.fs_values);
1003 let counts = std::mem::take(&mut self.fs_value_counts);
1004 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1005 return;
1006 }
1007 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1008 return;
1009 }
1010
1011 // Shadow prune — ruby's declarator shape is `assignment`. A
1012 // constant-typed LHS has no named children → constants are never
1013 // counted (never pruned); identifier LHSes (and each identifier of a
1014 // multiple-assign left) bump.
1015 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1016 let mut dstack: Vec<Node> = vec![root];
1017 let mut dvisited = 0usize;
1018 while let Some(n) = dstack.pop() {
1019 if dvisited >= MAX_VALUE_REF_NODES {
1020 break;
1021 }
1022 dvisited += 1;
1023 if n.kind() == "assignment" {
1024 let left = n
1025 .child_by_field_name("left")
1026 .or_else(|| n.child_by_field_name("pattern"))
1027 .or_else(|| n.named_child(0));
1028 if let Some(left) = left {
1029 if left.kind() == "identifier" {
1030 let nm = self.text(left);
1031 if targets.contains_key(nm) {
1032 *decl_counts.entry(nm).or_insert(0) += 1;
1033 }
1034 } else {
1035 for i in 0..left.named_child_count() {
1036 if let Some(c) = left.named_child(i) {
1037 if c.kind() == "identifier" {
1038 let nm = self.text(c);
1039 if targets.contains_key(nm) {
1040 *decl_counts.entry(nm).or_insert(0) += 1;
1041 }
1042 }
1043 }
1044 }
1045 }
1046 }
1047 }
1048 for i in 0..n.named_child_count() {
1049 if let Some(c) = n.named_child(i) {
1050 dstack.push(c);
1051 }
1052 }
1053 }
1054 let shadowed: Vec<String> = decl_counts
1055 .iter()
1056 .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1))
1057 .map(|(nm, _)| nm.to_string())

Callers 1

extractFunction · 0.45

Calls 8

is_generated_fileFunction · 0.85
edge_kind_indexFunction · 0.85
putMethod · 0.80
push_edgeMethod · 0.80
getMethod · 0.65
unwrapMethod · 0.60
textMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected