(&mut self, root: Node<'t>)
| 1548 | // --- value references ------------------------------------------------------------- |
| 1549 | |
| 1550 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 1551 | let scopes = std::mem::take(&mut self.value_scopes); |
| 1552 | let mut targets = std::mem::take(&mut self.fs_values); |
| 1553 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 1554 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 1555 | return; |
| 1556 | } |
| 1557 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 1558 | return; |
| 1559 | } |
| 1560 | |
| 1561 | // Shadow prune — TWO cases resolve for swift: property_declaration |
| 1562 | // (firstSimpleIdentifier over the name/binding pattern; guard-let/ |
| 1563 | // if-let bindings have no property_declaration → never prune) AND the |
| 1564 | // shared `assignment` case — a declared-then-assigned `let X: T` |
| 1565 | // followed by `X = …` branches counts one bump per assignment (the |
| 1566 | // directly_assignable_expression's simple_identifier child), pruning |
| 1567 | // X exactly as the wasm arm does (caught by the swift-nio sweep). |
| 1568 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 1569 | let mut dstack: Vec<Node> = vec![root]; |
| 1570 | let mut dvisited = 0usize; |
| 1571 | while let Some(n) = dstack.pop() { |
| 1572 | if dvisited >= MAX_VALUE_REF_NODES { |
| 1573 | break; |
| 1574 | } |
| 1575 | dvisited += 1; |
| 1576 | if n.kind() == "assignment" { |
| 1577 | let left = n |
| 1578 | .child_by_field_name("left") |
| 1579 | .or_else(|| n.child_by_field_name("pattern")) |
| 1580 | .or_else(|| n.named_child(0)); |
| 1581 | if let Some(left) = left { |
| 1582 | if left.kind() == "identifier" { |
| 1583 | let nm = self.text(left); |
| 1584 | if targets.contains_key(nm) { |
| 1585 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1586 | } |
| 1587 | } else { |
| 1588 | for i in 0..left.named_child_count() { |
| 1589 | let Some(c) = left.named_child(i) else { continue }; |
| 1590 | if matches!(c.kind(), "identifier" | "simple_identifier") { |
| 1591 | let nm = self.text(c); |
| 1592 | if targets.contains_key(nm) { |
| 1593 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1594 | } |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | if n.kind() == "property_declaration" { |
| 1601 | let vd = (0..n.named_child_count()) |
| 1602 | .filter_map(|i| n.named_child(i)) |
| 1603 | .find(|c| c.kind() == "variable_declaration"); // kotlin shape — None for swift |
| 1604 | let id = match vd { |
| 1605 | Some(vd) => (0..vd.named_child_count()) |
| 1606 | .filter_map(|i| vd.named_child(i)) |
| 1607 | .find(|c| c.kind() == "simple_identifier"), |
no test coverage detected