Skip to content

Lua extractor misses bare require() statements (no assignment) #3320

Description

@artbylmz

Summary

graphify.extract._import_lua only extracts an imports edge from Lua require(...) calls when they appear inside a variable_declaration node (i.e. local x = require("mod")). The far more common Neovim-config idiom — a bare require("mod") statement with no assignment — produces no edge at all.

This makes graphify's dependency graph badly undercount structure for any Lua/Neovim config, since files like init.lua typically do:

require("config.lazy")
require("config.options")
require("config.keymaps")

with no local assignment.

Repro

from pathlib import Path
from graphify.extract import extract

# bare require() - no edge
Path("a").mkdir(exist_ok=True)
Path("a/init.lua").write_text('require("config.lazy")\n')
Path("a/config.lazy.lua").write_text('-- lazy config\n')  # or lua/config/lazy.lua per module path
r1 = extract([Path("a/init.lua"), Path("a/config.lazy.lua")], cache_root=Path("a"))
print(r1["edges"])  # []

# assigned require() - edge produced correctly
Path("b").mkdir(exist_ok=True)
Path("b/init.lua").write_text('local ok = require("config.lazy")\n')
Path("b/config.lazy.lua").write_text('-- lazy config\n')
r2 = extract([Path("b/init.lua"), Path("b/config.lazy.lua")], cache_root=Path("b"))
print(r2["edges"])  # [{'source': 'init', 'target': 'config_lazy', 'relation': 'imports', ...}]

Confirmed against a real 14-file LazyVim/Neovim config where init.lua calls require("config.lazy") (bare) and every lua/config/*.lua / lua/plugins/*.lua file loaded this way ended up with zero import edges — resulting in a graph with 13 nodes but only 2 edges, all "contains" (function-in-file) relationships.

Expected

_import_lua should also fire on bare call-expression statements (a require(...) call used as a standalone statement, not just when assigned to a variable), so the common require("module")-with-no-assignment idiom resolves to an imports edge like the assigned form does.

Environment

  • graphifyy installed via uv tool install graphifyy
  • Reproduced via graphify.extract.extract() directly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions