From 6325a21905419c43152e4c91315f98b05d67663d Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Thu, 24 Oct 2024 20:22:37 +0200 Subject: [PATCH] fix: setting `lazy = false` marks plugin as eager (#108) --- lua/lz/n/handler/init.lua | 10 +++++++--- spec/hooks_spec.lua | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lua/lz/n/handler/init.lua b/lua/lz/n/handler/init.lua index 4231e2a..15c9101 100644 --- a/lua/lz/n/handler/init.lua +++ b/lua/lz/n/handler/init.lua @@ -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`. diff --git a/spec/hooks_spec.lua b/spec/hooks_spec.lua index 33a90a1..74618be 100644 --- a/spec/hooks_spec.lua +++ b/spec/hooks_spec.lua @@ -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)