(&mut self, root: Node<'t>)
| 1419 | // --- value references -------------------------------------------------------------- |
| 1420 | |
| 1421 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 1422 | let scopes = std::mem::take(&mut self.value_scopes); |
| 1423 | let mut targets = std::mem::take(&mut self.fs_values); |
| 1424 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 1425 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 1426 | return; |
| 1427 | } |
| 1428 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 1429 | return; |
| 1430 | } |
| 1431 | |
| 1432 | // Shadow prune — kotlin cases: property_declaration (its |
| 1433 | // variable_declaration's first simple_identifier; destructuring bumps |
| 1434 | // nothing) AND the shared `assignment` case (the swift-sweep lesson — |
| 1435 | // directly_assignable_expression children bump). |
| 1436 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 1437 | let mut dstack: Vec<Node> = vec![root]; |
| 1438 | let mut dvisited = 0usize; |
| 1439 | while let Some(n) = dstack.pop() { |
| 1440 | if dvisited >= MAX_VALUE_REF_NODES { |
| 1441 | break; |
| 1442 | } |
| 1443 | dvisited += 1; |
| 1444 | if n.kind() == "assignment" { |
| 1445 | let left = n |
| 1446 | .child_by_field_name("left") |
| 1447 | .or_else(|| n.child_by_field_name("pattern")) |
| 1448 | .or_else(|| n.named_child(0)); |
| 1449 | if let Some(left) = left { |
| 1450 | if left.kind() == "identifier" { |
| 1451 | let nm = self.text(left); |
| 1452 | if targets.contains_key(nm) { |
| 1453 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1454 | } |
| 1455 | } else { |
| 1456 | for i in 0..left.named_child_count() { |
| 1457 | let Some(c) = left.named_child(i) else { continue }; |
| 1458 | if matches!(c.kind(), "identifier" | "simple_identifier") { |
| 1459 | let nm = self.text(c); |
| 1460 | if targets.contains_key(nm) { |
| 1461 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1462 | } |
| 1463 | } |
| 1464 | } |
| 1465 | } |
| 1466 | } |
| 1467 | } |
| 1468 | if n.kind() == "property_declaration" { |
| 1469 | let vd = (0..n.named_child_count()) |
| 1470 | .filter_map(|i| n.named_child(i)) |
| 1471 | .find(|c| c.kind() == "variable_declaration"); |
| 1472 | if let Some(vd) = vd { |
| 1473 | let id = (0..vd.named_child_count()) |
| 1474 | .filter_map(|i| vd.named_child(i)) |
| 1475 | .find(|c| c.kind() == "simple_identifier"); |
| 1476 | if let Some(id) = id { |
| 1477 | let nm = self.text(id); |
| 1478 | if targets.contains_key(nm) { |
no test coverage detected