MCPcopy Index your code
hub / github.com/tirth8205/code-review-graph / _extract_lua_constructs

Method _extract_lua_constructs

code_review_graph/parser.py:3428–3486  ·  view source on GitHub ↗

Handle Lua-specific AST constructs. Returns True if the child was fully handled and should be skipped by the main loop. Handles: - variable_declaration with require() -> IMPORTS_FROM edge - variable_declaration with function_definition -> named Function node

(
        self,
        child,
        node_type: str,
        source: bytes,
        language: str,
        file_path: str,
        nodes: list[NodeInfo],
        edges: list[EdgeInfo],
        enclosing_class: Optional[str],
        enclosing_func: Optional[str],
        import_map: Optional[dict[str, str]],
        defined_names: Optional[set[str]],
        _depth: int,
    )

Source from the content-addressed store, hash-verified

3426 # ------------------------------------------------------------------
3427
3428 def _extract_lua_constructs(
3429 self,
3430 child,
3431 node_type: str,
3432 source: bytes,
3433 language: str,
3434 file_path: str,
3435 nodes: list[NodeInfo],
3436 edges: list[EdgeInfo],
3437 enclosing_class: Optional[str],
3438 enclosing_func: Optional[str],
3439 import_map: Optional[dict[str, str]],
3440 defined_names: Optional[set[str]],
3441 _depth: int,
3442 ) -> bool:
3443 """Handle Lua-specific AST constructs.
3444
3445 Returns True if the child was fully handled and should be skipped
3446 by the main loop.
3447
3448 Handles:
3449 - variable_declaration with require() -> IMPORTS_FROM edge
3450 - variable_declaration with function_definition -> named Function node
3451 - function_declaration with dot/method name -> Function with table parent
3452 - top-level require() call -> IMPORTS_FROM edge
3453 """
3454 # --- variable_declaration: require() or anonymous function ---
3455 if node_type == "variable_declaration":
3456 return self._handle_lua_variable_declaration(
3457 child, source, language, file_path, nodes, edges,
3458 enclosing_class, enclosing_func,
3459 import_map, defined_names, _depth,
3460 )
3461
3462 # --- function_declaration with dot/method table name ---
3463 if node_type == "function_declaration":
3464 return self._handle_lua_table_function(
3465 child, source, language, file_path, nodes, edges,
3466 enclosing_class, enclosing_func,
3467 import_map, defined_names, _depth,
3468 )
3469
3470 # --- Top-level require() not wrapped in variable_declaration ---
3471 if node_type == "function_call" and not enclosing_func:
3472 req_target = self._lua_get_require_target(child)
3473 if req_target is not None:
3474 resolved = self._resolve_module_to_file(
3475 req_target, file_path, language,
3476 )
3477 edges.append(EdgeInfo(
3478 kind="IMPORTS_FROM",
3479 source=file_path,
3480 target=resolved if resolved else req_target,
3481 file_path=file_path,
3482 line=child.start_point[0] + 1,
3483 ))
3484 return True
3485

Callers 1

_extract_from_treeMethod · 0.95

Calls 5

EdgeInfoClass · 0.85

Tested by

no test coverage detected