Skip to content

Commit

Permalink
fix: setting lazy = false marks plugin as eager
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Oct 24, 2024
1 parent 409fe85 commit 60c1556
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lua/lz/n/handler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ 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, _)
return spec[spec_field] ~= nil
end)
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)
end

---Mutates the `plugin`.
Expand Down
25 changes: 25 additions & 0 deletions spec/hooks_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,29 @@ describe("hooks", function()
})
assert.True(afterRun)
end)
describe("regression-#187", function()
it("hook run when `lazy = false`", function()
local beforeAllRun = false
local beforeRun = false
local afterRun = false
lz.load({
{
"neorg",
lazy = false,
beforeAll = function()
beforeAllRun = true
end,
before = function()
beforeRun = true
end,
after = function()
afterRun = true
end,
},
})
assert.True(beforeAllRun)
assert.True(beforeRun)
assert.True(afterRun)
end)
end)
end)

0 comments on commit 60c1556

Please sign in to comment.