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

Method visit

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

Source from the content-addressed store, hash-verified

421 // --- the main walk (visitNode, tree-sitter.ts:936-1303) ---------------
422
423 fn visit(&mut self, node: Node<'t>) {
424 stack_guard!();
425 let kind = node.kind();
426
427 // The visitNode hook (lua.ts:105-151) runs FIRST.
428 if kind == "function_call" {
429 if let Some(module) = self.require_module(node) {
430 self.emit_require(node, &module);
431 // Consumed → scanFnRefSubtree (tree-sitter.ts:951).
432 self.scan_fn_ref_subtree(node, 0);
433 return;
434 }
435 // falls through — extractCall claims it below
436 } else if kind == "variable_declaration" {
437 // `local x = require(...)` — dig requires out of the initializer
438 // the variable branch will skip. Always falls through.
439 let mut cursor = node.walk();
440 let assign = node.named_children(&mut cursor).find(|c| c.kind() == "assignment_statement");
441 if let Some(assign) = assign {
442 let mut ac = assign.walk();
443 let expr_list = assign.named_children(&mut ac).find(|c| c.kind() == "expression_list");
444 if let Some(expr_list) = expr_list {
445 let mut ec = expr_list.walk();
446 let vals: Vec<Node<'t>> = expr_list.named_children(&mut ec).collect();
447 for val in vals {
448 if val.kind() == "function_call" {
449 if let Some(module) = self.require_module(val) {
450 self.emit_require(val, &module);
451 }
452 }
453 }
454 }
455 }
456 }
457
458 // maybeCaptureFnRefs (tree-sitter.ts:990).
459 self.maybe_capture_fn_refs(node);
460
461 // The dispatch ladder — lua/luau rows only.
462 if kind == "function_declaration" {
463 // isInsideClassLikeNode is always false (no class-like kinds).
464 self.extract_function(node);
465 return; // skipChildren — the body walk handles children
466 }
467 if self.is_luau && kind == "type_definition" {
468 let skip = self.extract_type_alias(node);
469 if skip {
470 return;
471 }
472 // plain path returns false → children re-visited (the
473 // typeof(require(...)) alias+import pair rides this).
474 } else if matches!(kind, "variable_declaration" | "assignment_statement") {
475 self.extract_variable(node);
476 // Initializer subtrees are never walked — candidates only.
477 self.scan_fn_ref_subtree(node, 0);
478 return; // skipChildren
479 } else if kind == "function_call" {
480 self.extract_call(node);

Callers 1

extractFunction · 0.45

Calls 10

require_moduleMethod · 0.80
emit_requireMethod · 0.80
walkMethod · 0.80
scan_fn_ref_subtreeMethod · 0.45
collectMethod · 0.45
maybe_capture_fn_refsMethod · 0.45
extract_functionMethod · 0.45
extract_type_aliasMethod · 0.45
extract_variableMethod · 0.45
extract_callMethod · 0.45

Tested by

no test coverage detected