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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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

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