Skip to content

Commit

Permalink
feat: support explicit lazy=false (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoriya authored Jan 1, 2025
1 parent 32be28a commit 5a6d5fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lua/lz/n/handler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ end
---@return boolean
local function is_lazy(spec)
---@diagnostic disable-next-line: undefined-field
return spec.lazy
or vim.iter(handlers):any(function(spec_field, _)
-- PERF: This should be simpler and more performant than
-- filtering out "lazy" spec fields. However, this also
-- assumes that 'false' means a handler is disabled.
return spec[spec_field] and spec[spec_field] ~= nil
end)
if spec.lazy ~= nil then
---@diagnostic disable-next-line: undefined-field
return spec.lazy
end
return vim.iter(handlers):any(function(spec_field, _)
-- PERF: This should be simpler and more performant than
-- filtering out "lazy" spec fields. However, this also
-- assumes that 'false' means a handler is disabled.
return spec[spec_field] and spec[spec_field] ~= nil
end)
end

---Mutates the `plugin`.
Expand Down
16 changes: 16 additions & 0 deletions spec/lz_n_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,21 @@ describe("lz.n", function()
cmd = { "Single" },
})
end)
it("eagerly load if lazy=False", function()
local spy_load = spy.on(loader, "_load")
lz.load({
{
"single.nvim",
cmd = "Single",
lazy = false,
},
})
assert.spy(spy_load).called(1)
assert.spy(spy_load).called_with({
name = "single.nvim",
cmd = { "Single" },
lazy = false,
})
end)
end)
end)

0 comments on commit 5a6d5fa

Please sign in to comment.