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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

810 // --- function-as-value capture (#756) — LUA_SPEC ----------------------
811
812 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
813 // LUA_SPEC dispatch: arguments → args; assignment_statement → rhs
814 // (no field — last named child; param-storage skip via namedChild(0));
815 // field → value (field 'value', last-named-child fallback).
816 let mode: &str = match node.kind() {
817 "arguments" => "args",
818 "assignment_statement" => "rhs",
819 "field" => "value",
820 _ => return,
821 };
822 if self.stack.is_empty() {
823 return;
824 }
825 let from = self.top_row();
826
827 let mut values: Vec<Node<'t>> = Vec::new();
828 match mode {
829 "args" => {
830 let mut cursor = node.walk();
831 for c in node.named_children(&mut cursor) {
832 values.push(c);
833 }
834 }
835 "rhs" => {
836 // No `field` in the rule → RHS = LAST named child (the
837 // expression_list). Param-storage skip: lhs =
838 // left/lhs/target field ?? namedChild(0) when ≥2 children;
839 // its trailing identifier vs the whole RHS text.
840 let count = node.named_child_count();
841 let rhs = if count > 0 { node.named_child(count - 1) } else { None };
842 if let Some(rhs) = rhs {
843 let lhs = node
844 .child_by_field_name("left")
845 .or_else(|| node.child_by_field_name("lhs"))
846 .or_else(|| node.child_by_field_name("target"))
847 .or_else(|| if count >= 2 { node.named_child(0) } else { None });
848 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
849 let lhs_last = util::lhs_last_name()
850 .captures(lhs_text)
851 .and_then(|c| c.get(1))
852 .map(|m| m.as_str());
853 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
854 values.push(rhs);
855 }
856 }
857 }
858 _ => {
859 // value — the `value` field (keyed AND positional table
860 // fields carry it), falling back to the last named child.
861 let v = node.child_by_field_name("value").or_else(|| {
862 let count = node.named_child_count();
863 if count > 0 { node.named_child(count - 1) } else { None }
864 });
865 if let Some(v) = v {
866 values.push(v);
867 }
868 }
869 }

Callers 3

visitMethod · 0.45
visit_bodyMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected