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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

1584 // --- function-as-value refs (KOTLIN_SPEC, function-ref.ts:240) ------------------
1585
1586 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1587 enum Mode {
1588 Args,
1589 Rhs,
1590 }
1591 let mode = match node.kind() {
1592 "value_arguments" => Mode::Args,
1593 "assignment" => Mode::Rhs, // NO field — RHS = LAST named child
1594 _ => return,
1595 };
1596 if self.stack.is_empty() {
1597 return;
1598 }
1599 let from = self.top_row();
1600
1601 let mut values: Vec<Node> = Vec::new();
1602 match mode {
1603 Mode::Args => {
1604 for i in 0..node.named_child_count() {
1605 if let Some(c) = node.named_child(i) {
1606 values.push(c);
1607 }
1608 }
1609 }
1610 Mode::Rhs => {
1611 let rhs = if node.named_child_count() > 0 {
1612 node.named_child(node.named_child_count() - 1)
1613 } else {
1614 None
1615 };
1616 if let Some(rhs) = rhs {
1617 let lhs = node
1618 .child_by_field_name("left")
1619 .or_else(|| node.child_by_field_name("lhs"))
1620 .or_else(|| node.child_by_field_name("target"))
1621 .or_else(|| {
1622 if node.named_child_count() >= 2 { node.named_child(0) } else { None }
1623 });
1624 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
1625 let lhs_last = util::lhs_last_name()
1626 .captures(lhs_text)
1627 .and_then(|c| c.get(1))
1628 .map(|m| m.as_str());
1629 let rhs_text = self.text(rhs).trim();
1630 if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) {
1631 values.push(rhs);
1632 }
1633 }
1634 }
1635 }
1636
1637 for v in values {
1638 self.normalize_fn_ref_value(v, from, 0);
1639 }
1640 }
1641
1642 fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32) {
1643 stack_guard!();

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 6

pushMethod · 0.80
mapMethod · 0.80
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected