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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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