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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1511 // --- value refs -------------------------------------------------------------
1512
1513 fn flush_value_refs(&mut self, root: Node<'t>) {
1514 let scopes = std::mem::take(&mut self.value_scopes);
1515 let mut targets = std::mem::take(&mut self.fs_values);
1516 let counts = std::mem::take(&mut self.fs_value_counts);
1517 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1518 return;
1519 }
1520 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1521 return;
1522 }
1523
1524 // Shadow prune — rust declarator shapes: const_item/static_item (name
1525 // field) and let_declaration (the shadow source: `pattern` field; a
1526 // tuple pattern bumps every named child).
1527 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1528 let mut bump = |decl_counts: &mut HashMap<&'t str, u32>, name_node: Option<Node<'t>>, src: &'t str, targets: &HashMap<String, u32>| {
1529 if let Some(n) = name_node {
1530 if matches!(n.kind(), "identifier" | "simple_identifier") {
1531 let nm = &src[n.byte_range()];
1532 if targets.contains_key(nm) {
1533 *decl_counts.entry(nm).or_insert(0) += 1;
1534 }
1535 }
1536 }
1537 };
1538 let mut dstack: Vec<Node> = vec![root];
1539 let mut dvisited = 0usize;
1540 while let Some(n) = dstack.pop() {
1541 if dvisited >= MAX_VALUE_REF_NODES {
1542 break;
1543 }
1544 dvisited += 1;
1545 match n.kind() {
1546 "const_item" | "static_item" => {
1547 bump(&mut decl_counts, n.child_by_field_name("name"), self.src, &targets)
1548 }
1549 "let_declaration" => {
1550 let left = n
1551 .child_by_field_name("left")
1552 .or_else(|| n.child_by_field_name("pattern"))
1553 .or_else(|| n.named_child(0));
1554 if let Some(left) = left {
1555 if left.kind() == "identifier" {
1556 bump(&mut decl_counts, Some(left), self.src, &targets);
1557 } else {
1558 for i in 0..left.named_child_count() {
1559 bump(&mut decl_counts, left.named_child(i), self.src, &targets);
1560 }
1561 }
1562 }
1563 }
1564 _ => {}
1565 }
1566 for i in 0..n.named_child_count() {
1567 if let Some(c) = n.named_child(i) {
1568 dstack.push(c);
1569 }
1570 }

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