Skip to content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ zpack provides a single user command, `:ZPack`, with subcommands. Rename it with
| `:ZPack[!] restore [plugin]` | Restore plugins to the lockfile state; `!` skips the confirm buffer |
| `:ZPack[!] clean` | Remove plugins no longer in your spec, after listing them and asking; `!` doesn't ask |
| `:ZPack[!] build [plugin]` | Run a plugin's build hook; `!` runs every plugin's build hook |
| `:ZPack[!] load [plugin]` | Load an unloaded plugin; `!` loads all unloaded plugins |
| `:ZPack[!] load [plugin]` | Load an unloaded plugin; `!` loads all unloaded plugins whose `cond` isn't false |
| `:ZPack[!] delete [plugin]` | Remove a plugin; `!` removes all plugins |
| `:ZPack[!] sync` | Update everything, then clean, like `:Lazy sync`; `!` doesn't ask before deleting |
| `:ZPack reload {plugin}` | Re-source a plugin without restarting, like `:Lazy reload` |
Expand Down
19 changes: 12 additions & 7 deletions doc/zpack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ with |zpack-setup-cmd_name|; a short name like `Z` or `Zp` saves typing.

:ZPack[!] load [plugin]
Load the named plugin. `:ZPack! load` loads every plugin that
hasn't loaded yet. With neither a name nor `!` it only warns.
Tab completion lists unloaded plugins.
hasn't loaded yet, apart from those whose `cond` is false;
name one to load it anyway. With neither a name nor `!` it
only warns. Tab completion lists unloaded plugins whose `cond`
is true.

:ZPack[!] delete [plugin]
Remove the named plugin from disk. `:ZPack! delete` removes
Expand Down Expand Up @@ -1255,8 +1257,10 @@ The plugin data object passed to hooks and trigger functions:
-- names, as in lazy.nvim
main = string?, -- The spec's `main`, in every hook.
-- Without one, the detected module,
-- set before the first `config` runs
-- and nil until then
-- set before `opts` functions and
-- `config` run on each load,
-- `:ZPack reload` included, and nil
-- until then
}
<

Expand Down Expand Up @@ -1289,9 +1293,10 @@ main (string?)
The spec's `main` (|zpack-Spec.main|), set in every hook,
trigger function and `cond`, as in lazy.nvim. Without one,
nil until zpack detects the module, which it does only for a
plugin with `opts` or `config`, after its `opts` functions
and before `config` (or the automatic `setup()`) first runs.
It stays nil if detection finds none.
plugin with `opts` or `config`, before its `opts` functions
and `config` (or the automatic `setup()`) run, on the first
load and again on each `:ZPack reload`. It stays nil if
detection finds none.

==============================================================================
9. EVENTSPEC REFERENCE *zpack-eventspec-reference*
Expand Down
2 changes: 1 addition & 1 deletion docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The plugin data object passed to hooks and trigger functions:
name = string, -- Resolved plugin name (alias for spec.name, as in lazy.nvim)
dir = string, -- Plugin directory (alias for path, as in lazy.nvim)
dependencies = string[], -- Sorted list of resolved dependency names, as in lazy.nvim
main = string?, -- The spec's `main`, in every hook. Without one, the detected module, set before the first `config` runs and nil until then
main = string?, -- The spec's `main`, in every hook. Without one, the detected module, set before `opts` functions and `config` run on each load (`:ZPack reload` included) and nil until then
}
```

Expand Down
2 changes: 2 additions & 0 deletions lua/zpack/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ Sub.reload = {
end
end

if plugin then plugin.main = spec.main or nil end

-- init runs once at startup; reload re-runs it (fresh-load contract).
-- Type-guard: try_call_hook ERRORs on a missing hook, and startup's
-- caller pre-filters via ctx.src_with_init.
Expand Down
3 changes: 1 addition & 2 deletions lua/zpack/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ local function check_plugins()
vim.health.info(('loading: %d'):format(counts.loading))
end
if counts.installing > 0 then
local cmd_name = (state.config and state.config.cmd_name) or 'ZPack'
vim.health.warn(('installing: %d — not yet on disk'):format(counts.installing), {
('Restart Neovim, or run :%s update, once installation finishes.'):format(cmd_name),
'Restart Neovim to install them.',
})
end
if counts.disabled > 0 then
Expand Down
1 change: 1 addition & 0 deletions lua/zpack/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ M.setup_lazy_build_tracking = function()
util.autocmd('PackChanged', function(event)
if event.data.kind == "update" or event.data.kind == "install" then
util.reset_lsdir_cache()
vim.loader.reset(event.data.path)
require('zpack.module_loader').reset_lookup_cache()
M.load_and_build(event.data.spec.src)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/zpack/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ M.is_nop_rhs = function(rhs)
end

---`maparg()` for one of `vim.keymap.set`'s modes: it takes abbreviations as a flag
---and reads `!` as normal mode, so ask for insert mode, which `!` maps too.
---and reads `!` as `:map`'s modes, so ask for insert mode, which `!` maps too.
---@param lhs string
---@param mode string
---@return table map Empty when `lhs` isn't mapped
Expand Down
2 changes: 1 addition & 1 deletion lua/zpack/plugin_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function M.run_config(src, plugin)
local registry_entry = state.spec_registry[src]
local spec = registry_entry.merged_spec --[[@as zpack.Spec]]
local label = (plugin and plugin.spec and plugin.spec.name) or src
local main = utils.resolve_main(plugin)
-- resolve_opts is the single authoritative path for opts; it walks
-- sorted_specs fresh so function-form opts compose correctly.
local opts_ok, resolved_opts = pcall(
Expand All @@ -55,7 +56,6 @@ function M.run_config(src, plugin)
utils.schedule_notify(("Failed to run config for %s: %s"):format(label, tostring(resolved_opts)), vim.log.levels.ERROR)
return
end
local main = utils.resolve_main(plugin)

if type(spec.config) == "function" then
local config_fn = spec.config --[[@as fun(plugin: zpack.Plugin, opts: table)]]
Expand Down
4 changes: 0 additions & 4 deletions lua/zpack/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ M.name_to_src = {}
---@type { [string]: boolean }
M.lazy_parent_cache = {}

---@type { [string]: boolean }
M.resolve_main_not_found = {}

---@type { [string]: boolean }
M.src_with_pending_build = {}

Expand All @@ -56,7 +53,6 @@ M.remove_plugin = function(plugin_name, src)
M.src_to_pack_spec[src] = nil
M.name_to_src[plugin_name] = nil
M.lazy_parent_cache[src] = nil
M.resolve_main_not_found[src] = nil

M.dependency_graph[src] = nil
M.reverse_dependency_graph[src] = nil
Expand Down
6 changes: 3 additions & 3 deletions lua/zpack/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

---Plugin data passed to load callback from vim.pack.add and forwarded to
---spec hooks (init/config/opts/cond/build/deactivate). zpack's own fields are
---`spec`, `path`, and `main` (the spec's, else detected before the first
---`config`); lazy.nvim parity adds
---`spec`, `path`, and `main` (the spec's, else detected before each load's
---`opts` functions and `config`); lazy.nvim parity adds
---`name` (alias for spec.name), `dir` (alias for path), and `dependencies`
---(sorted list of resolved dependency names from this plugin's outgoing
---deps in the resolved spec tree).
Expand All @@ -36,7 +36,7 @@
---@field name? string Resolved plugin name (alias for spec.name; lazy.nvim parity)
---@field dir? string Plugin directory (alias for path; lazy.nvim parity)
---@field dependencies? string[] Sorted list of dependency names (lazy.nvim parity)
---@field main? string The spec's `main`, else the detected main module name (set before the first `config` runs)
---@field main? string The spec's `main`, else the detected main module name (set before `opts` functions and `config` run on each load, `:ZPack reload` included)

---@alias zpack.EventValue string|string[]|zpack.EventSpec|(string|zpack.EventSpec)[]
---@alias zpack.CmdValue string|string[]
Expand Down
17 changes: 3 additions & 14 deletions lua/zpack/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,22 +343,16 @@ end
---Resolve the main module for a plugin (for auto-setup)
---Inspired by lazy.nvim's loader.get_main()
---The spec's `main` is on the plugin from registration, so it is returned as is.
---Results are cached in plugin.main (for found modules) and state.resolve_main_not_found (for not-found)
---A found module is cached in plugin.main.
---@param plugin zpack.Plugin
---@return string? main_module The main module name, or nil if not found
M.resolve_main = function(plugin)
if plugin.main ~= nil then
return plugin.main
end

local cache_key = plugin.spec.src
if state.resolve_main_not_found[cache_key] then
return nil
end

local name = plugin.spec.name
if not name then
state.resolve_main_not_found[cache_key] = true
return nil
end

Expand Down Expand Up @@ -389,13 +383,8 @@ M.resolve_main = function(plugin)
-- No Lua module is named like the plugin: take a compiled one that is, else
-- the plugin's only module whatever its name: none-ls.nvim's `null-ls`.
local main = named_compiled or (#mods == 1 and mods[1]) or nil
if main then
plugin.main = main
return main
end

state.resolve_main_not_found[cache_key] = true
return nil
plugin.main = main
return main
end

return M
28 changes: 28 additions & 0 deletions tests/health_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,34 @@ describe("Health Check", function()
"Plugins section should report a registered count")
end)

it("advises a restart, not :ZPack update, for a plugin that isn't on disk", function()
vim.pack.add = function(specs)
for _, pack_spec in ipairs(specs) do
pack_spec.name = pack_spec.name or pack_spec.src:match('[^/]+$')
_G.test_state.registered_pack_specs[pack_spec.name] = pack_spec
end
end
require('zpack').setup({
spec = { { 'test/declined' } },
defaults = { confirm = false },
})
helpers.flush_pending()

local report, restore = capture_health()
run_check()
restore()

local advice
for _, item in ipairs(section(report, 'Plugins').items) do
if item.kind == 'warn' and item.msg:find('installing: 1', 1, true) then
advice = table.concat(item.advice, ' ')
end
end
assert.is_not_nil(advice)
assert.is_truthy(advice:find('Restart Neovim', 1, true))
assert.is_falsy(advice:find('update', 1, true))
end)

it("surfaces an invalid merged config", function()
require('zpack').setup({ spec = {}, defaults = { confirm = 'yes' } })
helpers.flush_pending()
Expand Down
Loading
Loading