MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / flush_value_refs

Method flush_value_refs

codegraph-kernel/src/dart.rs:2478–2576  ·  view source on GitHub ↗
(&mut self, root: Node<'t>)

Source from the content-addressed store, hash-verified

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

Callers 1

extractFunction · 0.45

Calls 12

is_generated_fileFunction · 0.85
edge_kind_indexFunction · 0.85
pushMethod · 0.80
mapMethod · 0.80
push_edgeMethod · 0.80
textMethod · 0.65
getMethod · 0.65
putMethod · 0.65
unwrapMethod · 0.60
takeFunction · 0.50
walkMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected