mirror of https://github.com/folke/lazy.nvim.git
feat: keep track what loaded a plugin
This commit is contained in:
parent
e59dc377d5
commit
4df73f167d
|
@ -15,6 +15,8 @@ M.types = {
|
||||||
|
|
||||||
---@type table<LoaderType, table<string, string[]>>|{init: string[]}
|
---@type table<LoaderType, table<string, string[]>>|{init: string[]}
|
||||||
M.loaders = nil
|
M.loaders = nil
|
||||||
|
---@type LazyPlugin[]
|
||||||
|
M.loading = {}
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
function M.add(plugin)
|
function M.add(plugin)
|
||||||
|
@ -59,7 +61,7 @@ function M.setup()
|
||||||
Util.track("loader_events")
|
Util.track("loader_events")
|
||||||
for event, plugins in pairs(M.loaders.event) do
|
for event, plugins in pairs(M.loaders.event) do
|
||||||
if event == "VimEnter" and vim.v.vim_did_enter == 1 then
|
if event == "VimEnter" and vim.v.vim_did_enter == 1 then
|
||||||
M.load(plugins)
|
M.load(plugins, { event = event })
|
||||||
else
|
else
|
||||||
local user_event = event:match("User (.*)")
|
local user_event = event:match("User (.*)")
|
||||||
vim.api.nvim_create_autocmd(user_event and "User" or event, {
|
vim.api.nvim_create_autocmd(user_event and "User" or event, {
|
||||||
|
@ -68,7 +70,7 @@ function M.setup()
|
||||||
pattern = user_event,
|
pattern = user_event,
|
||||||
callback = function()
|
callback = function()
|
||||||
Util.track("event: " .. (user_event or event))
|
Util.track("event: " .. (user_event or event))
|
||||||
M.load(plugins)
|
M.load(plugins, { event = event })
|
||||||
Util.track()
|
Util.track()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -85,7 +87,7 @@ function M.setup()
|
||||||
group = group,
|
group = group,
|
||||||
callback = function()
|
callback = function()
|
||||||
Util.track("filetype: " .. ft)
|
Util.track("filetype: " .. ft)
|
||||||
M.load(plugins)
|
M.load(plugins, { ft = ft })
|
||||||
Util.track()
|
Util.track()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -98,7 +100,7 @@ function M.setup()
|
||||||
vim.keymap.set("n", keys, function()
|
vim.keymap.set("n", keys, function()
|
||||||
vim.keymap.del("n", keys)
|
vim.keymap.del("n", keys)
|
||||||
Util.track("keys: " .. keys)
|
Util.track("keys: " .. keys)
|
||||||
M.load(plugins)
|
M.load(plugins, { keys = keys })
|
||||||
vim.api.nvim_input(keys)
|
vim.api.nvim_input(keys)
|
||||||
Util.track()
|
Util.track()
|
||||||
end)
|
end)
|
||||||
|
@ -140,7 +142,7 @@ function M.init_plugins()
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
if plugin.opt == false then
|
if plugin.opt == false then
|
||||||
M.load(plugin)
|
M.load(plugin, { package = "start" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Util.track()
|
Util.track()
|
||||||
|
@ -154,7 +156,21 @@ function M.module(modname)
|
||||||
local name = modname:sub(1, idx - 1)
|
local name = modname:sub(1, idx - 1)
|
||||||
local plugins = M.loaders.module[name]
|
local plugins = M.loaders.module[name]
|
||||||
if plugins then
|
if plugins then
|
||||||
M.load(plugins)
|
local reason = { require = modname }
|
||||||
|
if #M.loading == 0 then
|
||||||
|
local f = 3
|
||||||
|
while not reason.source do
|
||||||
|
local info = debug.getinfo(f, "S")
|
||||||
|
f = f + 1
|
||||||
|
if not info then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if info.what ~= "C" then
|
||||||
|
reason.source = info.source:sub(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
M.load(plugins, reason)
|
||||||
-- M.loaders.module[name] = nil
|
-- M.loaders.module[name] = nil
|
||||||
end
|
end
|
||||||
idx = modname:find(".", idx + 1, true)
|
idx = modname:find(".", idx + 1, true)
|
||||||
|
@ -170,7 +186,8 @@ function M.module(modname)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugins string|LazyPlugin|string[]|LazyPlugin[]
|
---@param plugins string|LazyPlugin|string[]|LazyPlugin[]
|
||||||
function M.load(plugins)
|
---@param reason {[string]:string}
|
||||||
|
function M.load(plugins, reason)
|
||||||
if type(plugins) == "string" or plugins.name then
|
if type(plugins) == "string" or plugins.name then
|
||||||
---@diagnostic disable-next-line: assign-type-mismatch
|
---@diagnostic disable-next-line: assign-type-mismatch
|
||||||
plugins = { plugins }
|
plugins = { plugins }
|
||||||
|
@ -183,20 +200,26 @@ function M.load(plugins)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not plugin.loaded then
|
if not plugin.loaded then
|
||||||
plugin.loaded = true
|
plugin.loaded = vim.deepcopy(reason or {})
|
||||||
|
if #M.loading > 0 then
|
||||||
|
plugin.loaded.plugin = M.loading[#M.loading].name
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(M.loading, plugin)
|
||||||
|
|
||||||
Util.track(plugin.name)
|
Util.track(plugin.name)
|
||||||
M.packadd(plugin)
|
M.packadd(plugin)
|
||||||
|
|
||||||
if plugin.requires then
|
if plugin.requires then
|
||||||
M.load(plugin.requires)
|
M.load(plugin.requires, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
if plugin.config then
|
if plugin.config then
|
||||||
plugin.config()
|
plugin.config()
|
||||||
end
|
end
|
||||||
|
|
||||||
Util.track()
|
plugin.loaded.time = Util.track().time
|
||||||
|
table.remove(M.loading)
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.cmd("do User LazyRender")
|
vim.cmd("do User LazyRender")
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -21,11 +21,12 @@ local M = {}
|
||||||
---@field module? string|string[]
|
---@field module? string|string[]
|
||||||
---@field keys? string|string[]
|
---@field keys? string|string[]
|
||||||
---@field requires? string[]
|
---@field requires? string[]
|
||||||
---@field loaded? boolean
|
---@field loaded? {[string]:string, time:number}
|
||||||
---@field installed? boolean
|
---@field installed? boolean
|
||||||
---@field run? string|fun()
|
---@field run? string|fun()
|
||||||
---@field tasks? LazyTask[]
|
---@field tasks? LazyTask[]
|
||||||
---@field dirty? boolean
|
---@field dirty? boolean
|
||||||
|
---@field updated? {from:string, to:string}
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
function M.plugin(plugin)
|
function M.plugin(plugin)
|
||||||
|
|
Loading…
Reference in New Issue