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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1429 // --- value references --------------------------------------------------------------
1430
1431 fn flush_value_refs(&mut self, root: Node<'t>) {
1432 let scopes = std::mem::take(&mut self.value_scopes);
1433 let mut targets = std::mem::take(&mut self.fs_values);
1434 let counts = std::mem::take(&mut self.fs_value_counts);
1435 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1436 return;
1437 }
1438 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1439 return;
1440 }
1441
1442 // Shadow prune — kotlin cases: property_declaration (its
1443 // variable_declaration's first simple_identifier; destructuring bumps
1444 // nothing) AND the shared `assignment` case (the swift-sweep lesson —
1445 // directly_assignable_expression children bump).
1446 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1447 let mut dstack: Vec<Node> = vec![root];
1448 let mut dvisited = 0usize;
1449 while let Some(n) = dstack.pop() {
1450 if dvisited >= MAX_VALUE_REF_NODES {
1451 break;
1452 }
1453 dvisited += 1;
1454 if n.kind() == "assignment" {
1455 let left = n
1456 .child_by_field_name("left")
1457 .or_else(|| n.child_by_field_name("pattern"))
1458 .or_else(|| n.named_child(0));
1459 if let Some(left) = left {
1460 if left.kind() == "identifier" {
1461 let nm = self.text(left);
1462 if targets.contains_key(nm) {
1463 *decl_counts.entry(nm).or_insert(0) += 1;
1464 }
1465 } else {
1466 for i in 0..left.named_child_count() {
1467 let Some(c) = left.named_child(i) else { continue };
1468 if matches!(c.kind(), "identifier" | "simple_identifier") {
1469 let nm = self.text(c);
1470 if targets.contains_key(nm) {
1471 *decl_counts.entry(nm).or_insert(0) += 1;
1472 }
1473 }
1474 }
1475 }
1476 }
1477 }
1478 if n.kind() == "property_declaration" {
1479 let vd = (0..n.named_child_count())
1480 .filter_map(|i| n.named_child(i))
1481 .find(|c| c.kind() == "variable_declaration");
1482 if let Some(vd) = vd {
1483 let id = (0..vd.named_child_count())
1484 .filter_map(|i| vd.named_child(i))
1485 .find(|c| c.kind() == "simple_identifier");
1486 if let Some(id) = id {
1487 let nm = self.text(id);
1488 if targets.contains_key(nm) {

Callers 1

extractFunction · 0.45

Calls 8

is_generated_fileFunction · 0.85
edge_kind_indexFunction · 0.85
push_edgeMethod · 0.80
textMethod · 0.65
getMethod · 0.65
putMethod · 0.65
unwrapMethod · 0.60
collectMethod · 0.45

Tested by

no test coverage detected