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

Method extract_variable

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

Source from the content-addressed store, hash-verified

557 // --- extractVariable — the lua/luau branch (2538-2549, 2789-2805) -----
558
559 fn extract_variable(&mut self, node: Node<'t>) {
560 // isConst absent → kind is ALWAYS `variable`; docstring from the
561 // DECLARATION node; isExported = hook ?? false → false for BOTH
562 // dialects (luau's slice sees `local …`).
563 let docstring = preceding_docstring(node, self.src);
564 let is_exported = self.is_exported_of(node).unwrap_or(false);
565
566 let mut cursor = node.walk();
567 let assign = node
568 .named_children(&mut cursor)
569 .find(|c| c.kind() == "assignment_statement")
570 .unwrap_or(node);
571 let mut ac = assign.walk();
572 let var_list = assign.named_children(&mut ac).find(|c| c.kind() == "variable_list");
573 let mut ec = assign.walk();
574 let expr_list = assign.named_children(&mut ec).find(|c| c.kind() == "expression_list");
575 let values: Vec<Node<'t>> = match expr_list {
576 Some(el) => {
577 let mut c = el.walk();
578 el.named_children(&mut c).collect()
579 }
580 None => Vec::new(),
581 };
582 let targets: Vec<Node<'t>> = match var_list {
583 Some(vl) => {
584 let mut c = vl.walk();
585 vl.named_children(&mut c).collect()
586 }
587 None => Vec::new(),
588 };
589 for (i, name_node) in targets.iter().enumerate() {
590 let Some((name, receiver, full_name)) = self.lua_assignment_target(*name_node) else {
591 continue;
592 };
593 let value = values.get(i).copied();
594 if let Some(value) = value {
595 if value.kind() == "function_definition" {
596 self.extract_lua_function_value(
597 value,
598 name,
599 receiver,
600 docstring.clone(),
601 );
602 continue;
603 }
604 if value.kind() == "table_constructor" {
605 self.extract_lua_table_functions(value, full_name);
606 }
607 }
608 // Dotted assignments update table members, not standalone vars.
609 if receiver.is_some() || node.kind() == "assignment_statement" {
610 continue;
611 }
612 // Positional value pairing; a missing value → NO signature key.
613 let signature = value.map(|v| util::init_signature(self.text(v)));
614 self.create_node(
615 "variable",
616 &name,

Callers 1

visitMethod · 0.45

Calls 12

preceding_docstringFunction · 0.85
init_signatureFunction · 0.85
is_exported_ofMethod · 0.80
walkMethod · 0.80
lua_assignment_targetMethod · 0.80
mapMethod · 0.80
getMethod · 0.65
textMethod · 0.65
collectMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected