Skip to content

Commit

Permalink
fix(event): dont use autocmd pattern to detect event retriggering. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 6, 2023
1 parent f145e6f commit bc89502
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lua/lazy/core/handler/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ function M:_add(value)
return
end
Util.track({ [self.type] = value })
local groups = M.get_augroups(event, pattern)
local groups = M.get_augroups(event)
-- load the plugins
Loader.load(self.active[value], { [self.type] = value })
-- check if any plugin created an event handler for this event and fire the group
self:trigger(event, pattern, groups)
self:trigger(event, groups)
Util.track()
end,
})
Expand All @@ -45,12 +45,11 @@ end

-- Get all augroups for the events
---@param event string
---@param pattern? string
function M.get_augroups(event, pattern)
function M.get_augroups(event)
local events = M.trigger_events[event] or { event }
---@type table<string,true>
local groups = {}
for _, autocmd in ipairs(vim.api.nvim_get_autocmds({ event = events, pattern = pattern })) do
for _, autocmd in ipairs(vim.api.nvim_get_autocmds({ event = events })) do
if autocmd.group then
groups[autocmd.group] = true
end
Expand All @@ -61,18 +60,17 @@ end
---@param event string|string[]
---@param pattern? string
---@param groups table<string,true>
function M:trigger(event, pattern, groups)
function M:trigger(event, groups)
local events = M.trigger_events[event] or { event }
---@cast events string[]
for _, e in ipairs(events) do
for _, autocmd in ipairs(vim.api.nvim_get_autocmds({ event = e, pattern = pattern })) do
for _, autocmd in ipairs(vim.api.nvim_get_autocmds({ event = e })) do
if autocmd.event == e and autocmd.group and not groups[autocmd.group] then
if Config.options.debug then
Util.info({
"# Firing Events",
" - **group:** `" .. autocmd.group_name .. "`",
" - **event:** " .. autocmd.event,
pattern and (" - **pattern:** " .. pattern),
})
end
Util.track({ event = autocmd.group_name })
Expand Down

0 comments on commit bc89502

Please sign in to comment.