mirror of https://github.com/folke/lazy.nvim.git
fix(ft): fix ft handlers to properly use new events. Fixes #1084
This commit is contained in:
parent
6687afae42
commit
e4ea874e33
|
@ -2,6 +2,13 @@ local Util = require("lazy.core.util")
|
|||
local Config = require("lazy.core.config")
|
||||
local Loader = require("lazy.core.loader")
|
||||
|
||||
---@class LazyEventOpts
|
||||
---@field event string
|
||||
---@field pattern? string
|
||||
---@field exclude? string[]
|
||||
---@field data? any
|
||||
---@field buf? number}
|
||||
|
||||
---@class LazyEventHandler:LazyHandler
|
||||
---@field events table<string,true>
|
||||
---@field group number
|
||||
|
@ -30,7 +37,7 @@ function M:_add(value)
|
|||
-- 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
|
||||
M.trigger({
|
||||
self:_trigger({
|
||||
event = ev.event,
|
||||
pattern = pattern,
|
||||
exclude = groups,
|
||||
|
@ -56,21 +63,26 @@ end
|
|||
---@param event string
|
||||
---@param pattern? string
|
||||
function M.get_augroups(event, pattern)
|
||||
local groups = {} ---@type number[]
|
||||
local groups = {} ---@type string[]
|
||||
for _, autocmd in ipairs(vim.api.nvim_get_autocmds({ event = event, pattern = pattern })) do
|
||||
if autocmd.group then
|
||||
table.insert(groups, autocmd.group)
|
||||
if autocmd.group_name then
|
||||
table.insert(groups, autocmd.group_name)
|
||||
end
|
||||
end
|
||||
return groups
|
||||
end
|
||||
|
||||
---@param opts {event:string, pattern?:string, exclude?:string[], data?:any, buf?:number}
|
||||
---@param opts LazyEventOpts
|
||||
function M:_trigger(opts)
|
||||
M.trigger(opts)
|
||||
end
|
||||
|
||||
---@param opts LazyEventOpts
|
||||
function M.trigger(opts)
|
||||
local done = {} ---@type table<string,true>
|
||||
for _, autocmd in ipairs(vim.api.nvim_get_autocmds({ event = opts.event, pattern = opts.pattern })) do
|
||||
local id = autocmd.event .. ":" .. (autocmd.group or "") ---@type string
|
||||
local skip = done[id] or (opts.exclude and vim.tbl_contains(opts.exclude, autocmd.group))
|
||||
local skip = done[id] or (opts.exclude and vim.tbl_contains(opts.exclude, autocmd.group_name))
|
||||
done[id] = true
|
||||
if autocmd.group and not skip then
|
||||
if Config.options.debug then
|
||||
|
|
|
@ -20,21 +20,21 @@ function M:add(plugin)
|
|||
end
|
||||
end
|
||||
|
||||
---@param pattern? string
|
||||
function M:trigger(_, pattern, _)
|
||||
for _, group in ipairs({ "filetypeplugin", "filetypeindent" }) do
|
||||
---@param opts LazyEventOpts
|
||||
function M:_trigger(opts)
|
||||
Util.try(function()
|
||||
if Config.options.debug then
|
||||
Util.info({
|
||||
"# Firing Events",
|
||||
" - **group:** `" .. group .. "`",
|
||||
" - **event:** FileType",
|
||||
pattern and (" - **pattern:** " .. pattern),
|
||||
opts.pattern and (" - **pattern:** " .. opts.pattern),
|
||||
opts.buf and (" - **buf:** " .. opts.buf),
|
||||
})
|
||||
end
|
||||
vim.api.nvim_exec_autocmds("FileType", { group = group, modeline = false, pattern = pattern })
|
||||
Util.track({ event = "FileType" })
|
||||
vim.api.nvim_exec_autocmds("FileType", { modeline = false, buffer = opts.buf })
|
||||
Util.track()
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Reference in New Issue