2022-12-05 21:45:50 +08:00
|
|
|
local Event = require("lazy.core.handler.event")
|
2022-12-30 00:26:38 +08:00
|
|
|
local Util = require("lazy.core.util")
|
2022-12-05 21:45:50 +08:00
|
|
|
local Loader = require("lazy.core.loader")
|
2022-12-30 01:06:40 +08:00
|
|
|
local Config = require("lazy.core.config")
|
2022-12-05 21:45:50 +08:00
|
|
|
|
|
|
|
---@class LazyFiletypeHandler:LazyEventHandler
|
|
|
|
local M = {}
|
|
|
|
M.extends = Event
|
|
|
|
|
|
|
|
---@param value string
|
2022-12-16 16:13:08 +08:00
|
|
|
function M:_event(value)
|
2022-12-05 21:45:50 +08:00
|
|
|
return "FileType " .. value
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param plugin LazyPlugin
|
2022-12-16 16:13:08 +08:00
|
|
|
function M:add(plugin)
|
|
|
|
self.super.add(self, plugin)
|
|
|
|
if plugin.ft then
|
|
|
|
Loader.ftdetect(plugin.dir)
|
|
|
|
end
|
2022-12-05 21:45:50 +08:00
|
|
|
end
|
|
|
|
|
2022-12-30 00:26:38 +08:00
|
|
|
---@param pattern? string
|
|
|
|
function M:trigger(_, pattern, _)
|
|
|
|
for _, group in ipairs({ "filetypeplugin", "filetypeindent" }) do
|
|
|
|
Util.try(function()
|
2022-12-30 01:06:40 +08:00
|
|
|
if Config.options.debug then
|
|
|
|
Util.info({
|
|
|
|
"# Firing Events",
|
|
|
|
" - **group:** `" .. group .. "`",
|
|
|
|
" - **event:** FileType",
|
|
|
|
pattern and (" - **pattern:** " .. pattern),
|
|
|
|
})
|
|
|
|
end
|
2022-12-30 00:26:38 +08:00
|
|
|
vim.api.nvim_exec_autocmds("FileType", { group = group, modeline = false, pattern = pattern })
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-05 21:45:50 +08:00
|
|
|
return M
|