fix(ft): only trigger filetypepluing and filetypeindent for ft handler. Fixes #228

This commit is contained in:
Folke Lemaitre 2022-12-29 17:26:38 +01:00
parent db043da829
commit 7de662d037
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 20 additions and 9 deletions

View File

@ -11,7 +11,6 @@ M.trigger_events = {
BufRead = { "BufReadPre", "BufRead" },
BufReadPost = { "BufReadPre", "BufRead", "BufReadPost" },
}
M.trigger_always = { "FileType" }
M.group = vim.api.nvim_create_augroup("lazy_handler_event", { clear = true })
---@param value string
@ -32,12 +31,8 @@ function M:_add(value)
local groups = M.get_augroups(event, pattern)
-- load the plugins
Loader.load(self.active[value], { [self.type] = value })
if vim.tbl_contains(M.trigger_always, event) then
vim.cmd("do " .. event)
else
-- check if any plugin created an event handler for this event and fire the group
M.trigger(event, pattern, groups)
end
-- check if any plugin created an event handler for this event and fire the group
self:trigger(event, pattern, groups)
Util.track()
end,
})
@ -66,7 +61,7 @@ end
---@param event string|string[]
---@param pattern? string
---@param groups table<string,true>
function M.trigger(event, pattern, groups)
function M:trigger(event, pattern, groups)
local events = M.trigger_events[event] or { event }
---@cast events string[]
for _, e in ipairs(events) do
@ -77,7 +72,7 @@ function M.trigger(event, pattern, groups)
"# Firing Events",
" - **group:** `" .. autocmd.group_name .. "`",
" - **event:** " .. autocmd.event,
pattern and "- **pattern:** ",
pattern and (" - **pattern:** " .. pattern),
})
end
Util.try(function()

View File

@ -1,4 +1,5 @@
local Event = require("lazy.core.handler.event")
local Util = require("lazy.core.util")
local Loader = require("lazy.core.loader")
---@class LazyFiletypeHandler:LazyEventHandler
@ -18,4 +19,19 @@ function M:add(plugin)
end
end
---@param pattern? string
function M:trigger(_, pattern, _)
for _, group in ipairs({ "filetypeplugin", "filetypeindent" }) do
Util.try(function()
Util.info({
"# Firing Events",
" - **group:** `" .. group .. "`",
" - **event:** FileType",
pattern and (" - **pattern:** " .. pattern),
})
vim.api.nvim_exec_autocmds("FileType", { group = group, modeline = false, pattern = pattern })
end)
end
end
return M