Skip to content

Lua require() dependencies do not appear as file-level edges in the final graph #1075

Closed

Description

@call-me-sean

Summary

It looks like Lua require() dependencies are not consistently preserved as file-level edges in the final graph.

Because of this, Lua files that are referenced via require() may not show the expected inbound dependency relationships.

Expected behavior

When Lua source contains imports such as:

local mod = require("foo.bar")
require("foo.baz")

the final graph should include a file-level dependency edge between the importing file and the imported Lua file.

Actual behavior

The final graph appears to keep other relationships such as structural containment and call edges, but Lua file-to-file dependency edges from require() are missing.

Possible cause

From a quick look at the current Lua extraction path, this may be related to how require() targets are extracted and resolved before graph construction.

In particular, it seems possible that:

  • only some require() forms are detected,
  • and/or the extracted target does not always match the corresponding file node in the graph.

If so, the dependency edge may be dropped during graph build.

Minimal example

a.lua

local b = require("pkg.b")
return b

pkg/b.lua

local M = {}
return M

Expected result:

  • a file-level dependency edge from a.lua to pkg/b.lua

Actual result:

  • the file-level dependency edge is missing

Suggested direction

It may help to:

  • support more Lua require() forms,
  • resolve Lua module paths to actual project file nodes,
  • and preserve those relationships as file-level edges in the final graph.

Thanks for taking a look.

Activity

  1. changed the title [-]Lua \ dependencies do not appear as file-level edges in the final graph[/-] [+]Lua require() dependencies do not appear as file-level edges in the final graph[/+] on May 29, 2026
  2. call-me-sean commented on May 29, 2026

    @call-me-sean
    Author

    Opened a fix PR for this:

    It includes the Lua require() file-level edge fix, follow-up path consistency fixes, and targeted validation notes.

  3. safishamsi commented on May 29, 2026

    @safishamsi
    Member

    Fixed in 5642c1b — _import_lua was taking only the last dot-segment of the module path and using the raw string as the edge target, which never matched the file node ID. Replaced with _resolve_lua_import_target that converts dots to path separators, probes the filesystem (up 6 parent dirs, tries .lua/.luau/init.lua variants), and returns the correct _make_id(str(resolved_path)). Graceful fallback on unresolved imports.

  4. call-me-sean commented on Jun 3, 2026

    @call-me-sean
    Author

    Thanks for the quick fix, and for linking it here.

    I re-tested this on our Lua corpus and on a smaller repro. The core issue in #1075 does look fixed: require("pkg.mod") is now resolved to a real file node instead of using only the last dot segment.

    That said, I still see a couple of gaps compared with the behavior we were validating in PR #1076:

    1. Bare require("pkg.bare") calls still appear to be missed in some cases, while assigned / nested / chained forms are picked up.
    2. In my local tests, the upstream fix emits imports edges, but not the imports_from file-level edges we were expecting for cross-file dependency analysis.

    For example, on our Nearby corpus I currently see:

    So from my side, the core target-ID bug is fixed, but there are still some remaining coverage / edge-semantics differences.

    PR #1076 is still open if helpful. It includes:

    • broader Lua require() coverage
    • file-level imports_from resolution
    • path consistency follow-up fixes
    • targeted validation notes

    Happy to help narrow this further or split the remaining gaps into a smaller follow-up if that makes review easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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