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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

1612 // --- function-as-value refs (KOTLIN_SPEC, function-ref.ts:240) ------------------
1613
1614 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1615 enum Mode {
1616 Args,
1617 Rhs,
1618 }
1619 let mode = match node.kind() {
1620 "value_arguments" => Mode::Args,
1621 "assignment" => Mode::Rhs, // NO field — RHS = LAST named child
1622 _ => return,
1623 };
1624 if self.stack.is_empty() {
1625 return;
1626 }
1627 let from = self.top_row();
1628
1629 let mut values: Vec<Node> = Vec::new();
1630 match mode {
1631 Mode::Args => {
1632 for c in node.named_children(&mut node.walk()) {
1633 values.push(c);
1634 }
1635 }
1636 Mode::Rhs => {
1637 let rhs = if node.named_child_count() > 0 {
1638 node.named_child(node.named_child_count() - 1)
1639 } else {
1640 None
1641 };
1642 if let Some(rhs) = rhs {
1643 let lhs = node
1644 .child_by_field_name("left")
1645 .or_else(|| node.child_by_field_name("lhs"))
1646 .or_else(|| node.child_by_field_name("target"))
1647 .or_else(|| {
1648 if node.named_child_count() >= 2 { node.named_child(0) } else { None }
1649 });
1650 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
1651 let lhs_last = util::lhs_last_name()
1652 .captures(lhs_text)
1653 .and_then(|c| c.get(1))
1654 .map(|m| m.as_str());
1655 let rhs_text = self.text(rhs).trim();
1656 if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) {
1657 values.push(rhs);
1658 }
1659 }
1660 }
1661 }
1662
1663 for v in values {
1664 self.normalize_fn_ref_value(v, from, 0);
1665 }
1666 }
1667
1668 fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32) {
1669 stack_guard!();

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected