(&mut self, root: Node<'t>)
| 2490 | // --- value-reference edges (:398-931) --------------------------------- |
| 2491 | |
| 2492 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 2493 | let scopes = std::mem::take(&mut self.value_scopes); |
| 2494 | let mut targets = std::mem::take(&mut self.fs_values); |
| 2495 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 2496 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 2497 | return; |
| 2498 | } |
| 2499 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 2500 | return; |
| 2501 | } |
| 2502 | |
| 2503 | // Shadow prune — the dart declarator shapes (:844-850): each bumps |
| 2504 | // its first identifier-typed named child. Uninitialized locals bump; |
| 2505 | // assignment_expression is NOT a prune case. |
| 2506 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 2507 | let mut dstack: Vec<Node> = vec![root]; |
| 2508 | let mut dvisited = 0usize; |
| 2509 | while let Some(n) = dstack.pop() { |
| 2510 | if dvisited >= MAX_VALUE_REF_NODES { |
| 2511 | break; |
| 2512 | } |
| 2513 | dvisited += 1; |
| 2514 | if matches!( |
| 2515 | n.kind(), |
| 2516 | "static_final_declaration" | "initialized_identifier" | "initialized_variable_definition" |
| 2517 | ) { |
| 2518 | let mut cursor = n.walk(); |
| 2519 | let id = n.named_children(&mut cursor).find(|c| c.kind() == "identifier"); |
| 2520 | if let Some(id) = id { |
| 2521 | let nm = self.text(id); |
| 2522 | if targets.contains_key(nm) { |
| 2523 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 2524 | } |
| 2525 | } |
| 2526 | } |
| 2527 | for i in 0..n.named_child_count() { |
| 2528 | if let Some(c) = n.named_child(i) { |
| 2529 | dstack.push(c); |
| 2530 | } |
| 2531 | } |
| 2532 | } |
| 2533 | let shadowed: Vec<String> = decl_counts |
| 2534 | .iter() |
| 2535 | .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1)) |
| 2536 | .map(|(nm, _)| nm.to_string()) |
| 2537 | .collect(); |
| 2538 | for nm in shadowed { |
| 2539 | targets.remove(&nm); |
| 2540 | } |
| 2541 | if targets.is_empty() { |
| 2542 | return; |
| 2543 | } |
| 2544 | |
| 2545 | let refs_kind = edge_kind_index("references").unwrap(); |
| 2546 | for scope in &scopes { |
| 2547 | let mut seen: HashSet<&str> = HashSet::new(); |
| 2548 | let mut stack: Vec<Node> = vec![scope.node]; |
| 2549 | // The Dart sibling-body pull (:883-892) is LIVE and load-bearing: |
no test coverage detected