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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1783 // --- value references --------------------------------------------------------------
1784
1785 fn flush_value_refs(&mut self, root: Node<'t>) {
1786 let scopes = std::mem::take(&mut self.value_scopes);
1787 let mut targets = std::mem::take(&mut self.fs_values);
1788 let counts = std::mem::take(&mut self.fs_value_counts);
1789 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1790 return;
1791 }
1792 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1793 return;
1794 }
1795
1796 // Shadow prune — kotlin cases: property_declaration (its
1797 // variable_declaration's first simple_identifier; destructuring bumps
1798 // nothing) AND the shared `assignment` case (the swift-sweep lesson —
1799 // directly_assignable_expression children bump).
1800 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1801 let mut dstack: Vec<Node> = vec![root];
1802 let mut dvisited = 0usize;
1803 while let Some(n) = dstack.pop() {
1804 if dvisited >= MAX_VALUE_REF_NODES {
1805 break;
1806 }
1807 dvisited += 1;
1808 if n.kind() == "assignment" {
1809 let left = n
1810 .child_by_field_name("left")
1811 .or_else(|| n.child_by_field_name("pattern"))
1812 .or_else(|| n.named_child(0));
1813 if let Some(left) = left {
1814 if left.kind() == "identifier" {
1815 let nm = self.text(left);
1816 if targets.contains_key(nm) {
1817 *decl_counts.entry(nm).or_insert(0) += 1;
1818 }
1819 } else {
1820 for i in 0..left.named_child_count() {
1821 let Some(c) = left.named_child(i) else { continue };
1822 if matches!(c.kind(), "identifier" | "simple_identifier") {
1823 let nm = self.text(c);
1824 if targets.contains_key(nm) {
1825 *decl_counts.entry(nm).or_insert(0) += 1;
1826 }
1827 }
1828 }
1829 }
1830 }
1831 }
1832 if n.kind() == "property_declaration" {
1833 let vd = (0..n.named_child_count())
1834 .filter_map(|i| n.named_child(i))
1835 .find(|c| c.kind() == "variable_declaration");
1836 if let Some(vd) = vd {
1837 let id = (0..vd.named_child_count())
1838 .filter_map(|i| vd.named_child(i))
1839 .find(|c| c.kind() == "simple_identifier");
1840 if let Some(id) = id {
1841 let nm = self.text(id);
1842 if targets.contains_key(nm) {

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