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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

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

Callers 1

extractFunction · 0.45

Calls 12

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
walkMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected