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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1452 // --- value references -------------------------------------------------------------
1453
1454 fn flush_value_refs(&mut self, root: Node<'t>) {
1455 let scopes = std::mem::take(&mut self.value_scopes);
1456 let mut targets = std::mem::take(&mut self.fs_values);
1457 let counts = std::mem::take(&mut self.fs_value_counts);
1458 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1459 return;
1460 }
1461 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1462 return;
1463 }
1464
1465 // Shadow prune — TWO cases resolve for swift: property_declaration
1466 // (firstSimpleIdentifier over the name/binding pattern; guard-let/
1467 // if-let bindings have no property_declaration → never prune) AND the
1468 // shared `assignment` case — a declared-then-assigned `let X: T`
1469 // followed by `X = …` branches counts one bump per assignment (the
1470 // directly_assignable_expression's simple_identifier child), pruning
1471 // X exactly as the wasm arm does (caught by the swift-nio sweep).
1472 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1473 let mut dstack: Vec<Node> = vec![root];
1474 let mut dvisited = 0usize;
1475 while let Some(n) = dstack.pop() {
1476 if dvisited >= MAX_VALUE_REF_NODES {
1477 break;
1478 }
1479 dvisited += 1;
1480 if n.kind() == "assignment" {
1481 let left = n
1482 .child_by_field_name("left")
1483 .or_else(|| n.child_by_field_name("pattern"))
1484 .or_else(|| n.named_child(0));
1485 if let Some(left) = left {
1486 if left.kind() == "identifier" {
1487 let nm = self.text(left);
1488 if targets.contains_key(nm) {
1489 *decl_counts.entry(nm).or_insert(0) += 1;
1490 }
1491 } else {
1492 for i in 0..left.named_child_count() {
1493 let Some(c) = left.named_child(i) else { continue };
1494 if matches!(c.kind(), "identifier" | "simple_identifier") {
1495 let nm = self.text(c);
1496 if targets.contains_key(nm) {
1497 *decl_counts.entry(nm).or_insert(0) += 1;
1498 }
1499 }
1500 }
1501 }
1502 }
1503 }
1504 if n.kind() == "property_declaration" {
1505 let vd = (0..n.named_child_count())
1506 .filter_map(|i| n.named_child(i))
1507 .find(|c| c.kind() == "variable_declaration"); // kotlin shape — None for swift
1508 let id = match vd {
1509 Some(vd) => (0..vd.named_child_count())
1510 .filter_map(|i| vd.named_child(i))
1511 .find(|c| c.kind() == "simple_identifier"),

Callers 1

extractFunction · 0.45

Calls 9

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