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 Config = require("lazy.core.config")
|
||||||
local Loader = require("lazy.core.loader")
|
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
|
---@class LazyEventHandler:LazyHandler
|
||||||
---@field events table<string,true>
|
---@field events table<string,true>
|
||||||
---@field group number
|
---@field group number
|
||||||
|
@ -30,7 +37,7 @@ function M:_add(value)
|
||||||
-- load the plugins
|
-- load the plugins
|
||||||
Loader.load(self.active[value], { [self.type] = value })
|
Loader.load(self.active[value], { [self.type] = value })
|
||||||
-- check if any plugin created an event handler for this event and fire the group
|
-- check if any plugin created an event handler for this event and fire the group
|
||||||
M.trigger({
|
self:_trigger({
|
||||||
event = ev.event,
|
event = ev.event,
|
||||||
pattern = pattern,
|
pattern = pattern,
|
||||||
exclude = groups,
|
exclude = groups,
|
||||||
|
@ -56,21 +63,26 @@ end
|
||||||
---@param event string
|
---@param event string
|
||||||
---@param pattern? string
|
---@param pattern? string
|
||||||
function M.get_augroups(event, pattern)
|
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
|
for _, autocmd in ipairs(vim.api.nvim_get_autocmds({ event = event, pattern = pattern })) do
|
||||||
if autocmd.group then
|
if autocmd.group_name then
|
||||||
table.insert(groups, autocmd.group)
|
table.insert(groups, autocmd.group_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return groups
|
return groups
|
||||||
end
|
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)
|
function M.trigger(opts)
|
||||||
local done = {} ---@type table<string,true>
|
local done = {} ---@type table<string,true>
|
||||||
for _, autocmd in ipairs(vim.api.nvim_get_autocmds({ event = opts.event, pattern = opts.pattern })) do
|
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 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
|
done[id] = true
|
||||||
if autocmd.group and not skip then
|
if autocmd.group and not skip then
|
||||||
if Config.options.debug then
|
if Config.options.debug then
|
||||||
|
|
|
@ -20,21 +20,21 @@ function M:add(plugin)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param pattern? string
|
---@param opts LazyEventOpts
|
||||||
function M:trigger(_, pattern, _)
|
function M:_trigger(opts)
|
||||||
for _, group in ipairs({ "filetypeplugin", "filetypeindent" }) do
|
|
||||||
Util.try(function()
|
Util.try(function()
|
||||||
if Config.options.debug then
|
if Config.options.debug then
|
||||||
Util.info({
|
Util.info({
|
||||||
"# Firing Events",
|
"# Firing Events",
|
||||||
" - **group:** `" .. group .. "`",
|
|
||||||
" - **event:** FileType",
|
" - **event:** FileType",
|
||||||
pattern and (" - **pattern:** " .. pattern),
|
opts.pattern and (" - **pattern:** " .. opts.pattern),
|
||||||
|
opts.buf and (" - **buf:** " .. opts.buf),
|
||||||
})
|
})
|
||||||
end
|
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
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in New Issue