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

Method visit

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

Source from the content-addressed store, hash-verified

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