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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

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