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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1531 // --- value refs -------------------------------------------------------------
1532
1533 fn flush_value_refs(&mut self, root: Node<'t>) {
1534 let scopes = std::mem::take(&mut self.value_scopes);
1535 let mut targets = std::mem::take(&mut self.fs_values);
1536 let counts = std::mem::take(&mut self.fs_value_counts);
1537 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1538 return;
1539 }
1540 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1541 return;
1542 }
1543
1544 // Shadow prune — rust declarator shapes: const_item/static_item (name
1545 // field) and let_declaration (the shadow source: `pattern` field; a
1546 // tuple pattern bumps every named child).
1547 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1548 let mut bump = |decl_counts: &mut HashMap<&'t str, u32>, name_node: Option<Node<'t>>, src: &'t str, targets: &HashMap<String, u32>| {
1549 if let Some(n) = name_node {
1550 if matches!(n.kind(), "identifier" | "simple_identifier") {
1551 let nm = &src[n.byte_range()];
1552 if targets.contains_key(nm) {
1553 *decl_counts.entry(nm).or_insert(0) += 1;
1554 }
1555 }
1556 }
1557 };
1558 let mut dstack: Vec<Node> = vec![root];
1559 let mut dvisited = 0usize;
1560 while let Some(n) = dstack.pop() {
1561 if dvisited >= MAX_VALUE_REF_NODES {
1562 break;
1563 }
1564 dvisited += 1;
1565 match n.kind() {
1566 "const_item" | "static_item" => {
1567 bump(&mut decl_counts, n.child_by_field_name("name"), self.src, &targets)
1568 }
1569 "let_declaration" => {
1570 let left = n
1571 .child_by_field_name("left")
1572 .or_else(|| n.child_by_field_name("pattern"))
1573 .or_else(|| n.named_child(0));
1574 if let Some(left) = left {
1575 if left.kind() == "identifier" {
1576 bump(&mut decl_counts, Some(left), self.src, &targets);
1577 } else {
1578 for i in 0..left.named_child_count() {
1579 bump(&mut decl_counts, left.named_child(i), self.src, &targets);
1580 }
1581 }
1582 }
1583 }
1584 _ => {}
1585 }
1586 for c in n.named_children(&mut n.walk()) {
1587 dstack.push(c);
1588 }
1589 }
1590 let shadowed: Vec<String> = decl_counts

Callers 1

extractFunction · 0.45

Calls 13

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

Tested by

no test coverage detected