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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

2072 // --- value-reference edges (:398-931) ---------------------------------
2073
2074 fn flush_value_refs(&mut self, root: Node<'t>) {
2075 let scopes = std::mem::take(&mut self.value_scopes);
2076 let mut targets = std::mem::take(&mut self.fs_values);
2077 let counts = std::mem::take(&mut self.fs_value_counts);
2078 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
2079 return;
2080 }
2081 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
2082 return;
2083 }
2084
2085 // Shadow prune — the dart declarator shapes (:844-850): each bumps
2086 // its first identifier-typed named child. Uninitialized locals bump;
2087 // assignment_expression is NOT a prune case.
2088 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
2089 let mut dstack: Vec<Node> = vec![root];
2090 let mut dvisited = 0usize;
2091 while let Some(n) = dstack.pop() {
2092 if dvisited >= MAX_VALUE_REF_NODES {
2093 break;
2094 }
2095 dvisited += 1;
2096 if matches!(
2097 n.kind(),
2098 "static_final_declaration" | "initialized_identifier" | "initialized_variable_definition"
2099 ) {
2100 let mut cursor = n.walk();
2101 let id = n.named_children(&mut cursor).find(|c| c.kind() == "identifier");
2102 if let Some(id) = id {
2103 let nm = self.text(id);
2104 if targets.contains_key(nm) {
2105 *decl_counts.entry(nm).or_insert(0) += 1;
2106 }
2107 }
2108 }
2109 for i in 0..n.named_child_count() {
2110 if let Some(c) = n.named_child(i) {
2111 dstack.push(c);
2112 }
2113 }
2114 }
2115 let shadowed: Vec<String> = decl_counts
2116 .iter()
2117 .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1))
2118 .map(|(nm, _)| nm.to_string())
2119 .collect();
2120 for nm in shadowed {
2121 targets.remove(&nm);
2122 }
2123 if targets.is_empty() {
2124 return;
2125 }
2126
2127 let refs_kind = edge_kind_index("references").unwrap();
2128 for scope in &scopes {
2129 let mut seen: HashSet<&str> = HashSet::new();
2130 let mut stack: Vec<Node> = vec![scope.node];
2131 // The Dart sibling-body pull (:883-892) is LIVE and load-bearing:

Callers 1

extractFunction · 0.45

Calls 12

is_generated_fileFunction · 0.85
edge_kind_indexFunction · 0.85
walkMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
push_edgeMethod · 0.80
textMethod · 0.65
getMethod · 0.65
putMethod · 0.65
unwrapMethod · 0.60
takeFunction · 0.50
collectMethod · 0.45

Tested by

no test coverage detected