(&mut self, root: Node<'t>)
| 440 | } |
| 441 | |
| 442 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 443 | let scopes = std::mem::take(&mut self.value_scopes); |
| 444 | let mut targets = std::mem::take(&mut self.fs_values); |
| 445 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 446 | if !self.variant.value_refs() || std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 447 | return; |
| 448 | } |
| 449 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | // Shadow prune: count declarators of each target name across the whole |
| 454 | // tree; more declarators than file-scope nodes ⇒ an inner re-binding |
| 455 | // shadows the target. (TS/JS declarators are `variable_declarator`; |
| 456 | // the other kinds in the TS switch belong to other grammars.) |
| 457 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 458 | let mut dstack: Vec<Node> = vec![root]; |
| 459 | let mut dvisited = 0usize; |
| 460 | while let Some(n) = dstack.pop() { |
| 461 | if dvisited >= MAX_VALUE_REF_NODES { |
| 462 | break; |
| 463 | } |
| 464 | dvisited += 1; |
| 465 | if n.kind() == "variable_declarator" { |
| 466 | if let Some(first) = n.named_child(0) { |
| 467 | if first.kind() == "identifier" { |
| 468 | let nm = self.text(first); |
| 469 | if targets.contains_key(nm) { |
| 470 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | for i in 0..n.named_child_count() { |
| 476 | if let Some(c) = n.named_child(i) { |
| 477 | dstack.push(c); |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | let shadowed: Vec<String> = decl_counts |
| 482 | .iter() |
| 483 | .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1)) |
| 484 | .map(|(nm, _)| nm.to_string()) |
| 485 | .collect(); |
| 486 | for nm in shadowed { |
| 487 | targets.remove(&nm); |
| 488 | } |
| 489 | if targets.is_empty() { |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | let refs_kind = edge_kind_index("references").unwrap(); |
| 494 | for scope in &scopes { |
| 495 | // Self-skip and per-scope dedupe compare node ID STRINGS (which |
| 496 | // collide for same-(kind, name, line) nodes), matching the TS side. |
| 497 | let mut seen: HashSet<&str> = HashSet::new(); |
| 498 | let mut stack: Vec<Node> = vec![scope.node]; |
| 499 | let mut visited = 0usize; |
no test coverage detected