refactor: use_lazy_file

This commit is contained in:
Folke Lemaitre 2023-10-06 18:35:17 +02:00
parent 6b4c872f2d
commit e1f5484c82
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -137,7 +137,6 @@ function M.setup(opts)
end, end,
}) })
M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil
if M.use_lazy_file then if M.use_lazy_file then
M.lazy_file() M.lazy_file()
end end
@ -252,6 +251,10 @@ function M.init()
if not M.did_init then if not M.did_init then
M.did_init = true M.did_init = true
vim.opt.rtp:append(require("lazy.core.config").spec.plugins.LazyVim.dir) vim.opt.rtp:append(require("lazy.core.config").spec.plugins.LazyVim.dir)
---@diagnostic disable-next-line: undefined-field
M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil
-- delay notifications till vim.notify was replaced or after 500ms -- delay notifications till vim.notify was replaced or after 500ms
require("lazyvim.util").lazy_notify() require("lazyvim.util").lazy_notify()
@ -263,19 +266,32 @@ function M.init()
local add = Plugin.Spec.add local add = Plugin.Spec.add
---@diagnostic disable-next-line: duplicate-set-field ---@diagnostic disable-next-line: duplicate-set-field
Plugin.Spec.add = function(self, plugin, ...) Plugin.Spec.add = function(self, plugin, ...)
if type(plugin) == "table" and M.renames[plugin[1]] then if type(plugin) == "table" then
require("lazy.core.util").warn( if M.renames[plugin[1]] then
("Plugin `%s` was renamed to `%s`.\nPlease update your config for `%s`"):format( require("lazy.core.util").warn(
plugin[1], ("Plugin `%s` was renamed to `%s`.\nPlease update your config for `%s`"):format(
M.renames[plugin[1]], plugin[1],
self.importing or "LazyVim" M.renames[plugin[1]],
), self.importing or "LazyVim"
{ title = "LazyVim" } ),
) { title = "LazyVim" }
plugin[1] = M.renames[plugin[1]] )
end plugin[1] = M.renames[plugin[1]]
if not M.use_lazy_file and type(plugin) == "table" and plugin.event == "LazyFile" then end
plugin.event = { "BufReadPost", "BufNewFile" } if not M.use_lazy_file and plugin.event then
if plugin.event == "LazyFile" then
plugin.event = { "BufReadPost", "BufNewFile" }
elseif type(plugin.event) == "table" then
local events = {} ---@type string[]
for i, event in ipairs(plugin.event) do
if event == "LazyFile" then
vim.list_extend(events, { "BufReadPost", "BufNewFile" })
else
events[#events + 1] = event
end
end
end
end
end end
return add(self, plugin, ...) return add(self, plugin, ...)
end end