Skip to content

fix(main): take a compiled module named like the plugin, as lazy.nvim does - #58

Merged
zuqini merged 9 commits into
mainfrom
main-detection-parity
Nov 15, 2026
Merged

zuqini merged 9 commits into
mainfrom
main-detection-parity

Conversation

@zuqini

@zuqini zuqini commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Follow-ups to #57.

Fix

  • main: a compiled module (.so/.dll) named like the plugin is now its main, as in lazy.nvim. foo.nvim with lua/foo.so beside another module got no main and the "set main explicitly" warning; it now gets foo. A matching Lua module still wins over the compiled one, so zeebar/init.lua beside zee_bar.so keeps zeebar (the perf: stop tracing zpack's startup code #52 case). lazy.nvim's choice there depends on pairs order.

This removes the "Known difference from lazy.nvim" that #57 documented.

Refactor

utils.top_module now reads .so/.dll itself and returns the module name and whether it is compiled. resolve_main and module_loader's claims_topmod each matched the suffixes on their own before. It checks suffixes with string.sub rather than patterns. With patterns, the move made claims_topmod 2.5× slower, and that showed in zb (inits150 +2.2 ms). With string.sub it is about 5× faster than before. claims_topmod answers the same for every top-level name require can produce, except the empty one from require('') or a name of only dots (the loader strips leading dots, so require('.x') asks for x): it no longer claims a junk file named literally .so or .dll.

Tests

Docs

  • :h zpack-Spec.main says a compiled module counts in the name match and the only-module rule, that a matching Lua module wins, and how a module name matches the plugin's.
  • New :h zpack.Plugin.main entry in the Plugin reference, including when a detected module is set.

Testing

  • luacheck and LuaLS are clean. The suite passes on nightly (1513) and v0.12.0 (1512).
  • zb check against the base: no lazy flips, structural or opts differences. Every perf row is within 1 ms of the base, and inits150 is about 0.7 ms faster on both nightly and 0.12. One row, file150 on 0.12, was flagged only for machine load in two runs; there it is −0.29 ms against the base, with a CI spanning 0.
  • A port of lazy.nvim's lsmod + get_main, run against 22 lua/ layouts: zpack now matches it on all but a file literally named .so. On main it also differed on both foo.so layouts.
  • On the final tip (f37feb1): zb check is ok, with no rows flagged and every row within ±0.6 ms of the base. In a real Neovim with a built lua/foo.so beside lua/bar.lua, main warns "Could not determine main module", and this branch calls foo.setup with the spec's opts, on install and on the next start.

@zuqini
zuqini merged commit 0e96646 into main Nov 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant