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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1356 }
1357
1358 fn flush_value_refs(&mut self, root: Node<'t>) {
1359 let scopes = std::mem::take(&mut self.value_scopes);
1360 let mut targets = std::mem::take(&mut self.fs_values);
1361 let counts = std::mem::take(&mut self.fs_value_counts);
1362 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1363 return;
1364 }
1365 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1366 return;
1367 }
1368
1369 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1370 let mut dstack: Vec<Node> = vec![root];
1371 let mut dvisited = 0usize;
1372 while let Some(n) = dstack.pop() {
1373 if dvisited >= MAX_VALUE_REF_NODES {
1374 break;
1375 }
1376 dvisited += 1;
1377 if n.kind() == "variable_declarator" {
1378 if let Some(first) = n.named_child(0) {
1379 if first.kind() == "identifier" {
1380 let nm = self.text(first);
1381 if targets.contains_key(nm) {
1382 *decl_counts.entry(nm).or_insert(0) += 1;
1383 }
1384 }
1385 }
1386 }
1387 for i in 0..n.named_child_count() {
1388 if let Some(c) = n.named_child(i) {
1389 dstack.push(c);
1390 }
1391 }
1392 }
1393 let shadowed: Vec<String> = decl_counts
1394 .iter()
1395 .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1))
1396 .map(|(nm, _)| nm.to_string())
1397 .collect();
1398 for nm in shadowed {
1399 targets.remove(&nm);
1400 }
1401 if targets.is_empty() {
1402 return;
1403 }
1404
1405 let refs_kind = edge_kind_index("references").unwrap();
1406 for scope in &scopes {
1407 // ID-string comparisons, matching the TS side (ids collide).
1408 let mut seen: HashSet<&str> = HashSet::new();
1409 let mut stack: Vec<Node> = vec![scope.node];
1410 let mut visited = 0usize;
1411 while let Some(n) = stack.pop() {
1412 if visited >= MAX_VALUE_REF_NODES {
1413 break;
1414 }
1415 visited += 1;

Callers 1

extractFunction · 0.45

Calls 12

is_generated_fileFunction · 0.85
edge_kind_indexFunction · 0.85
pushMethod · 0.80
mapMethod · 0.80
is_foreign_fieldMethod · 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