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