(&mut self, root: Node<'t>)
| 1557 | // --- value refs ------------------------------------------------------------- |
| 1558 | |
| 1559 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 1560 | let scopes = std::mem::take(&mut self.value_scopes); |
| 1561 | let mut targets = std::mem::take(&mut self.fs_values); |
| 1562 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 1563 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 1564 | return; |
| 1565 | } |
| 1566 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 1567 | return; |
| 1568 | } |
| 1569 | |
| 1570 | // Shadow prune — rust declarator shapes: const_item/static_item (name |
| 1571 | // field) and let_declaration (the shadow source: `pattern` field; a |
| 1572 | // tuple pattern bumps every named child). |
| 1573 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 1574 | let mut bump = |decl_counts: &mut HashMap<&'t str, u32>, name_node: Option<Node<'t>>, src: &'t str, targets: &HashMap<String, u32>| { |
| 1575 | if let Some(n) = name_node { |
| 1576 | if matches!(n.kind(), "identifier" | "simple_identifier") { |
| 1577 | let nm = &src[n.byte_range()]; |
| 1578 | if targets.contains_key(nm) { |
| 1579 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1580 | } |
| 1581 | } |
| 1582 | } |
| 1583 | }; |
| 1584 | let mut dstack: Vec<Node> = vec![root]; |
| 1585 | let mut dvisited = 0usize; |
| 1586 | while let Some(n) = dstack.pop() { |
| 1587 | if dvisited >= MAX_VALUE_REF_NODES { |
| 1588 | break; |
| 1589 | } |
| 1590 | dvisited += 1; |
| 1591 | match n.kind() { |
| 1592 | "const_item" | "static_item" => { |
| 1593 | bump(&mut decl_counts, n.child_by_field_name("name"), self.src, &targets) |
| 1594 | } |
| 1595 | "let_declaration" => { |
| 1596 | let left = n |
| 1597 | .child_by_field_name("left") |
| 1598 | .or_else(|| n.child_by_field_name("pattern")) |
| 1599 | .or_else(|| n.named_child(0)); |
| 1600 | if let Some(left) = left { |
| 1601 | if left.kind() == "identifier" { |
| 1602 | bump(&mut decl_counts, Some(left), self.src, &targets); |
| 1603 | } else { |
| 1604 | for i in 0..left.named_child_count() { |
| 1605 | bump(&mut decl_counts, left.named_child(i), self.src, &targets); |
| 1606 | } |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | _ => {} |
| 1611 | } |
| 1612 | for c in n.named_children(&mut n.walk()) { |
| 1613 | dstack.push(c); |
| 1614 | } |
| 1615 | } |
| 1616 | let shadowed: Vec<String> = decl_counts |
no test coverage detected