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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1558 // --- value refs -------------------------------------------------------------
1559
1560 fn flush_value_refs(&mut self, root: Node<'t>) {
1561 let scopes = std::mem::take(&mut self.value_scopes);
1562 let mut targets = std::mem::take(&mut self.fs_values);
1563 let counts = std::mem::take(&mut self.fs_value_counts);
1564 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1565 return;
1566 }
1567 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1568 return;
1569 }
1570
1571 // Shadow prune — rust declarator shapes: const_item/static_item (name
1572 // field) and let_declaration (the shadow source: `pattern` field; a
1573 // tuple pattern bumps every named child).
1574 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1575 let mut bump = |decl_counts: &mut HashMap<&'t str, u32>, name_node: Option<Node<'t>>, src: &'t str, targets: &HashMap<String, u32>| {
1576 if let Some(n) = name_node {
1577 if matches!(n.kind(), "identifier" | "simple_identifier") {
1578 let nm = &src[n.byte_range()];
1579 if targets.contains_key(nm) {
1580 *decl_counts.entry(nm).or_insert(0) += 1;
1581 }
1582 }
1583 }
1584 };
1585 let mut dstack: Vec<Node> = vec![root];
1586 let mut dvisited = 0usize;
1587 while let Some(n) = dstack.pop() {
1588 if dvisited >= MAX_VALUE_REF_NODES {
1589 break;
1590 }
1591 dvisited += 1;
1592 match n.kind() {
1593 "const_item" | "static_item" => {
1594 bump(&mut decl_counts, n.child_by_field_name("name"), self.src, &targets)
1595 }
1596 "let_declaration" => {
1597 let left = n
1598 .child_by_field_name("left")
1599 .or_else(|| n.child_by_field_name("pattern"))
1600 .or_else(|| n.named_child(0));
1601 if let Some(left) = left {
1602 if left.kind() == "identifier" {
1603 bump(&mut decl_counts, Some(left), self.src, &targets);
1604 } else {
1605 for i in 0..left.named_child_count() {
1606 bump(&mut decl_counts, left.named_child(i), self.src, &targets);
1607 }
1608 }
1609 }
1610 }
1611 _ => {}
1612 }
1613 for i in 0..n.named_child_count() {
1614 if let Some(c) = n.named_child(i) {
1615 dstack.push(c);
1616 }
1617 }

Callers 1

extractFunction · 0.45

Calls 12

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

Tested by

no test coverage detected