diff --git a/lua/lz/n/meta.lua b/lua/lz/n/meta.lua index 22ced50..ec19d98 100644 --- a/lua/lz/n/meta.lua +++ b/lua/lz/n/meta.lua @@ -8,8 +8,6 @@ error("Cannot import a meta module") --- --- Whether to enable this plugin. Useful to disable plugins under certain conditions. --- @field enabled? boolean|(fun():boolean) ---- Whether to lazy-load this plugin. Defaults to `false`. ---- @field lazy? boolean --- --- Only useful for lazy=false plugins to force loading certain plugins first. --- Default priority is 50 @@ -62,6 +60,8 @@ error("Cannot import a meta module") --- @field name string --- @class lz.n.Plugin: lz.n.PluginBase,lz.n.PluginHandlers,lz.n.PluginHooks +--- Whether to lazy-load this plugin. Defaults to `false`. +--- @field lazy? boolean --- @class lz.n.PluginSpec: lz.n.PluginBase,lz.n.PluginSpecHandlers,lz.n.PluginHooks diff --git a/lua/lz/n/spec.lua b/lua/lz/n/spec.lua index 1470952..a558af6 100644 --- a/lua/lz/n/spec.lua +++ b/lua/lz/n/spec.lua @@ -65,6 +65,8 @@ local function parse(spec) local ft_spec = spec.ft if ft_spec then result.event = result.event or {} + ---@diagnostic disable-next-line: inject-field + result.ft = nil end if type(ft_spec) == "string" then local ft = require("lz.n.handler.ft").parse(ft_spec) @@ -100,6 +102,7 @@ local function parse(spec) table.insert(result.cmd, _cmd_spec) end end + result.lazy = result.lazy or result.event ~= nil or result.keys ~= nil or result.cmd ~= nil return result end diff --git a/spec/lz_n_spec.lua b/spec/lz_n_spec.lua new file mode 100644 index 0000000..49b9702 --- /dev/null +++ b/spec/lz_n_spec.lua @@ -0,0 +1,46 @@ +local lz = require("lz.n") +local loader = require("lz.n.loader") +local spy = require("luassert.spy") + +describe("lz.n", function() + it("load", function() + local spy_load = spy.on(loader, "_load") + lz.load({ + { + name = "neorg", + }, + { + name = "crates.nvim", + ft = { "toml", "rust" }, + }, + { + name = "telescope.nvim", + keys = "tt", + cmd = "Telescope", + }, + }) + assert.spy(spy_load).called(1) + assert.spy(spy_load).called_with({ + name = "neorg", + lazy = false, + }) + vim.api.nvim_exec_autocmds("FileType", { pattern = "toml" }) + assert.spy(spy_load).called(2) + assert.spy(spy_load).called_with({ + name = "crates.nvim", + lazy = true, + event = { + require("lz.n.handler.ft").parse("toml"), + require("lz.n.handler.ft").parse("rust"), + }, + }) + vim.cmd.Telescope() + assert.spy(spy_load).called(3) + assert.spy(spy_load).called_with({ + name = "telescope.nvim", + lazy = true, + cmd = { "Telescope" }, + keys = { require("lz.n.handler.keys").parse("tt") }, + }) + end) +end)