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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

1498 // --- value references -------------------------------------------------------------
1499
1500 fn flush_value_refs(&mut self, root: Node<'t>) {
1501 let scopes = std::mem::take(&mut self.value_scopes);
1502 let mut targets = std::mem::take(&mut self.fs_values);
1503 let counts = std::mem::take(&mut self.fs_value_counts);
1504 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1505 return;
1506 }
1507 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1508 return;
1509 }
1510
1511 // Shadow prune — TWO cases resolve for swift: property_declaration
1512 // (firstSimpleIdentifier over the name/binding pattern; guard-let/
1513 // if-let bindings have no property_declaration → never prune) AND the
1514 // shared `assignment` case — a declared-then-assigned `let X: T`
1515 // followed by `X = …` branches counts one bump per assignment (the
1516 // directly_assignable_expression's simple_identifier child), pruning
1517 // X exactly as the wasm arm does (caught by the swift-nio sweep).
1518 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1519 let mut dstack: Vec<Node> = vec![root];
1520 let mut dvisited = 0usize;
1521 while let Some(n) = dstack.pop() {
1522 if dvisited >= MAX_VALUE_REF_NODES {
1523 break;
1524 }
1525 dvisited += 1;
1526 if n.kind() == "assignment" {
1527 let left = n
1528 .child_by_field_name("left")
1529 .or_else(|| n.child_by_field_name("pattern"))
1530 .or_else(|| n.named_child(0));
1531 if let Some(left) = left {
1532 if left.kind() == "identifier" {
1533 let nm = self.text(left);
1534 if targets.contains_key(nm) {
1535 *decl_counts.entry(nm).or_insert(0) += 1;
1536 }
1537 } else {
1538 for c in left.named_children(&mut left.walk()) {
1539 if matches!(c.kind(), "identifier" | "simple_identifier") {
1540 let nm = self.text(c);
1541 if targets.contains_key(nm) {
1542 *decl_counts.entry(nm).or_insert(0) += 1;
1543 }
1544 }
1545 }
1546 }
1547 }
1548 }
1549 if n.kind() == "property_declaration" {
1550 let vd = (0..n.named_child_count())
1551 .filter_map(|i| n.named_child(i))
1552 .find(|c| c.kind() == "variable_declaration"); // kotlin shape — None for swift
1553 let id = match vd {
1554 Some(vd) => (0..vd.named_child_count())
1555 .filter_map(|i| vd.named_child(i))
1556 .find(|c| c.kind() == "simple_identifier"),
1557 None => first_simple_identifier(n.child_by_field_name("name").or_else(|| {

Callers 1

extractFunction · 0.45

Calls 13

is_generated_fileFunction · 0.85
first_simple_identifierFunction · 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
walkMethod · 0.45

Tested by

no test coverage detected