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

Method visit

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

Source from the content-addressed store, hash-verified

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

Callers 1

extractFunction · 0.45

Calls 9

require_moduleMethod · 0.80
emit_requireMethod · 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