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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

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