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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1383 // --- value-reference edges (:398-931) ---------------------------------
1384
1385 fn flush_value_refs(&mut self, root: Node<'t>) {
1386 let scopes = std::mem::take(&mut self.value_scopes);
1387 let mut targets = std::mem::take(&mut self.fs_values);
1388 let counts = std::mem::take(&mut self.fs_value_counts);
1389 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1390 return;
1391 }
1392 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1393 return;
1394 }
1395
1396 // Shadow prune — the scala declarator shape: val_definition /
1397 // var_definition with an `identifier` pattern (tuple/case-class
1398 // patterns bump nothing).
1399 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1400 let mut dstack: Vec<Node> = vec![root];
1401 let mut dvisited = 0usize;
1402 while let Some(n) = dstack.pop() {
1403 if dvisited >= MAX_VALUE_REF_NODES {
1404 break;
1405 }
1406 dvisited += 1;
1407 if matches!(n.kind(), "val_definition" | "var_definition") {
1408 if let Some(pat) = n.child_by_field_name("pattern") {
1409 if pat.kind() == "identifier" {
1410 let nm = self.text(pat);
1411 if targets.contains_key(nm) {
1412 *decl_counts.entry(nm).or_insert(0) += 1;
1413 }
1414 }
1415 }
1416 }
1417 for i in 0..n.named_child_count() {
1418 if let Some(c) = n.named_child(i) {
1419 dstack.push(c);
1420 }
1421 }
1422 }
1423 let shadowed: Vec<String> = decl_counts
1424 .iter()
1425 .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1))
1426 .map(|(nm, _)| nm.to_string())
1427 .collect();
1428 for nm in shadowed {
1429 targets.remove(&nm);
1430 }
1431 if targets.is_empty() {
1432 return;
1433 }
1434
1435 let refs_kind = edge_kind_index("references").unwrap();
1436 for scope in &scopes {
1437 let mut seen: HashSet<&str> = HashSet::new();
1438 let mut stack: Vec<Node> = vec![scope.node];
1439 // The Dart/Pascal sibling-body pull (:891) — a next sibling of
1440 // kind function_body/block joins the scan. Effectively inert for
1441 // scala (bodies nest) but ported for fidelity.
1442 if let Some(sib) = scope.node.next_named_sibling() {

Callers 1

extractFunction · 0.45

Calls 11

is_generated_fileFunction · 0.85
edge_kind_indexFunction · 0.85
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