(&mut self, root: Node<'t>)
| 1802 | // --- value references -------------------------------------------------------------- |
| 1803 | |
| 1804 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 1805 | let scopes = std::mem::take(&mut self.value_scopes); |
| 1806 | let mut targets = std::mem::take(&mut self.fs_values); |
| 1807 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 1808 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 1809 | return; |
| 1810 | } |
| 1811 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 1812 | return; |
| 1813 | } |
| 1814 | |
| 1815 | // Shadow prune — kotlin cases: property_declaration (its |
| 1816 | // variable_declaration's first simple_identifier; destructuring bumps |
| 1817 | // nothing) AND the shared `assignment` case (the swift-sweep lesson — |
| 1818 | // directly_assignable_expression children bump). |
| 1819 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 1820 | let mut dstack: Vec<Node> = vec![root]; |
| 1821 | let mut dvisited = 0usize; |
| 1822 | while let Some(n) = dstack.pop() { |
| 1823 | if dvisited >= MAX_VALUE_REF_NODES { |
| 1824 | break; |
| 1825 | } |
| 1826 | dvisited += 1; |
| 1827 | if n.kind() == "assignment" { |
| 1828 | let left = n |
| 1829 | .child_by_field_name("left") |
| 1830 | .or_else(|| n.child_by_field_name("pattern")) |
| 1831 | .or_else(|| n.named_child(0)); |
| 1832 | if let Some(left) = left { |
| 1833 | if left.kind() == "identifier" { |
| 1834 | let nm = self.text(left); |
| 1835 | if targets.contains_key(nm) { |
| 1836 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1837 | } |
| 1838 | } else { |
| 1839 | for c in left.named_children(&mut left.walk()) { |
| 1840 | if matches!(c.kind(), "identifier" | "simple_identifier") { |
| 1841 | let nm = self.text(c); |
| 1842 | if targets.contains_key(nm) { |
| 1843 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1844 | } |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | if n.kind() == "property_declaration" { |
| 1851 | let vd = (0..n.named_child_count()) |
| 1852 | .filter_map(|i| n.named_child(i)) |
| 1853 | .find(|c| c.kind() == "variable_declaration"); |
| 1854 | if let Some(vd) = vd { |
| 1855 | let id = (0..vd.named_child_count()) |
| 1856 | .filter_map(|i| vd.named_child(i)) |
| 1857 | .find(|c| c.kind() == "simple_identifier"); |
| 1858 | if let Some(id) = id { |
| 1859 | let nm = self.text(id); |
| 1860 | if targets.contains_key(nm) { |
| 1861 | *decl_counts.entry(nm).or_insert(0) += 1; |
no test coverage detected