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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1604 // --- value references --------------------------------------------------------
1605
1606 fn flush_value_refs(&mut self, root: Node<'t>) {
1607 let scopes = std::mem::take(&mut self.value_scopes);
1608 let mut targets = std::mem::take(&mut self.fs_values);
1609 let counts = std::mem::take(&mut self.fs_value_counts);
1610 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1611 return;
1612 }
1613 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1614 return;
1615 }
1616
1617 // Shadow prune: count every variable_declarator declaring a target
1618 // name (field declarators AND method-body/top-level locals); more
1619 // declarations than file-scope captures → shadowed → dropped.
1620 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1621 let mut dstack: Vec<Node> = vec![root];
1622 let mut dvisited = 0usize;
1623 while let Some(n) = dstack.pop() {
1624 if dvisited >= MAX_VALUE_REF_NODES {
1625 break;
1626 }
1627 dvisited += 1;
1628 if n.kind() == "variable_declarator" {
1629 if let Some(first) = n.named_child(0) {
1630 if first.kind() == "identifier" {
1631 let nm = self.text(first);
1632 if targets.contains_key(nm) {
1633 *decl_counts.entry(nm).or_insert(0) += 1;
1634 }
1635 }
1636 }
1637 }
1638 // (property_declaration's bump is structurally null for C# — not ported.)
1639 for i in 0..n.named_child_count() {
1640 if let Some(c) = n.named_child(i) {
1641 dstack.push(c);
1642 }
1643 }
1644 }
1645 let shadowed: Vec<String> = decl_counts
1646 .iter()
1647 .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1))
1648 .map(|(nm, _)| nm.to_string())
1649 .collect();
1650 for nm in shadowed {
1651 targets.remove(&nm);
1652 }
1653 if targets.is_empty() {
1654 return;
1655 }
1656
1657 let refs_kind = edge_kind_index("references").unwrap();
1658 for scope in &scopes {
1659 // ID-string comparisons, matching the TS side (ids collide).
1660 let mut seen: HashSet<&str> = HashSet::new();
1661 let mut stack: Vec<Node> = vec![scope.node];
1662 let mut visited = 0usize;
1663 while let Some(n) = stack.pop() {

Callers 1

extractFunction · 0.45

Calls 11

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
collectMethod · 0.45

Tested by

no test coverage detected