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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1632 // --- value references --------------------------------------------------------
1633
1634 fn flush_value_refs(&mut self, root: Node<'t>) {
1635 let scopes = std::mem::take(&mut self.value_scopes);
1636 let mut targets = std::mem::take(&mut self.fs_values);
1637 let counts = std::mem::take(&mut self.fs_value_counts);
1638 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1639 return;
1640 }
1641 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1642 return;
1643 }
1644
1645 // Shadow prune: count every variable_declarator declaring a target
1646 // name (field declarators AND method-body/top-level locals); more
1647 // declarations than file-scope captures → shadowed → dropped.
1648 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1649 let mut dstack: Vec<Node> = vec![root];
1650 let mut dvisited = 0usize;
1651 while let Some(n) = dstack.pop() {
1652 if dvisited >= MAX_VALUE_REF_NODES {
1653 break;
1654 }
1655 dvisited += 1;
1656 if n.kind() == "variable_declarator" {
1657 if let Some(first) = n.named_child(0) {
1658 if first.kind() == "identifier" {
1659 let nm = self.text(first);
1660 if targets.contains_key(nm) {
1661 *decl_counts.entry(nm).or_insert(0) += 1;
1662 }
1663 }
1664 }
1665 }
1666 // (property_declaration's bump is structurally null for C# — not ported.)
1667 for i in 0..n.named_child_count() {
1668 if let Some(c) = n.named_child(i) {
1669 dstack.push(c);
1670 }
1671 }
1672 }
1673 let shadowed: Vec<String> = decl_counts
1674 .iter()
1675 .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1))
1676 .map(|(nm, _)| nm.to_string())
1677 .collect();
1678 for nm in shadowed {
1679 targets.remove(&nm);
1680 }
1681 if targets.is_empty() {
1682 return;
1683 }
1684
1685 let refs_kind = edge_kind_index("references").unwrap();
1686 for scope in &scopes {
1687 // ID-string comparisons, matching the TS side (ids collide).
1688 let mut seen: HashSet<&str> = HashSet::new();
1689 let mut stack: Vec<Node> = vec![scope.node];
1690 let mut visited = 0usize;
1691 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