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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

688 // --- function-as-value capture (#756) — LUA_SPEC ----------------------
689
690 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
691 // LUA_SPEC dispatch: arguments → args; assignment_statement → rhs
692 // (no field — last named child; param-storage skip via namedChild(0));
693 // field → value (field 'value', last-named-child fallback).
694 let mode: &str = match node.kind() {
695 "arguments" => "args",
696 "assignment_statement" => "rhs",
697 "field" => "value",
698 _ => return,
699 };
700 if self.stack.is_empty() {
701 return;
702 }
703 let from = self.top_row();
704
705 let mut values: Vec<Node<'t>> = Vec::new();
706 match mode {
707 "args" => {
708 let mut cursor = node.walk();
709 for c in node.named_children(&mut cursor) {
710 values.push(c);
711 }
712 }
713 "rhs" => {
714 // No `field` in the rule → RHS = LAST named child (the
715 // expression_list). Param-storage skip: lhs =
716 // left/lhs/target field ?? namedChild(0) when ≥2 children;
717 // its trailing identifier vs the whole RHS text.
718 let count = node.named_child_count();
719 let rhs = if count > 0 { node.named_child(count - 1) } else { None };
720 if let Some(rhs) = rhs {
721 let lhs = node
722 .child_by_field_name("left")
723 .or_else(|| node.child_by_field_name("lhs"))
724 .or_else(|| node.child_by_field_name("target"))
725 .or_else(|| if count >= 2 { node.named_child(0) } else { None });
726 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
727 let lhs_last = util::lhs_last_name()
728 .captures(lhs_text)
729 .and_then(|c| c.get(1))
730 .map(|m| m.as_str());
731 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
732 values.push(rhs);
733 }
734 }
735 }
736 _ => {
737 // value — the `value` field (keyed AND positional table
738 // fields carry it), falling back to the last named child.
739 let v = node.child_by_field_name("value").or_else(|| {
740 let count = node.named_child_count();
741 if count > 0 { node.named_child(count - 1) } else { None }
742 });
743 if let Some(v) = v {
744 values.push(v);
745 }
746 }
747 }

Callers 3

visitMethod · 0.45
visit_bodyMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected