fix!: run `init()` before loading start plugins. Fixes #107

This commit is contained in:
Folke Lemaitre 2022-12-22 18:46:43 +01:00
parent fb8287c73d
commit 2756a6f756
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 35 additions and 35 deletions

View File

@ -511,10 +511,10 @@ startup sequence for more flexibility and better performance.
In practice this means that step 10 of [Neovim Initialization](https://neovim.io/doc/user/starting.html#initialization) is done by Lazy: In practice this means that step 10 of [Neovim Initialization](https://neovim.io/doc/user/starting.html#initialization) is done by Lazy:
1. all plugins with `lazy=false` are loaded. This includes sourcing `/plugin` and `/ftdetect` files. (`/after` will not be sourced yet) 1. all the plugins' `init()` functions are executed
2. all files from `/plugin` and `/ftdetect` directories in you rtp are sourced (excluding `/after`) 2. all plugins with `lazy=false` are loaded. This includes sourcing `/plugin` and `/ftdetect` files. (`/after` will not be sourced yet)
3. all `/after/plugin` files are sourced (this inludes `/after` from plugins) 3. all files from `/plugin` and `/ftdetect` directories in you rtp are sourced (excluding `/after`)
4. all the plugins' `init()` functions are executed 4. all `/after/plugin` files are sourced (this inludes `/after` from plugins)
Files from runtime directories are always sourced in alphabetical order. Files from runtime directories are always sourced in alphabetical order.

View File

@ -58,36 +58,7 @@ function M.startup()
-- backup original rtp -- backup original rtp
local rtp = vim.opt.rtp:get() local rtp = vim.opt.rtp:get()
-- 1. load start plugin -- 1. run plugin init
Util.track({ start = "start" })
for _, plugin in pairs(Config.plugins) do
if plugin.lazy == false then
M.load(plugin, { start = "start" })
end
end
Util.track()
-- 2. load plugins from rtp, excluding after
Util.track({ start = "rtp plugins" })
for _, path in ipairs(rtp) do
if not path:find("after/?$") then
M.packadd(path)
end
end
Util.track()
-- 3. load after plugins
Util.track({ start = "after" })
for _, path in ipairs(vim.opt.rtp:get()) do
if path:find("after/?$") then
M.source_runtime(path, "plugin")
end
end
Util.track()
M.init_done = true
-- 4. run plugin init
Util.track({ start = "init" }) Util.track({ start = "init" })
for _, plugin in pairs(Config.plugins) do for _, plugin in pairs(Config.plugins) do
if plugin.init then if plugin.init then
@ -98,6 +69,35 @@ function M.startup()
end end
Util.track() Util.track()
-- 2. load start plugin
Util.track({ start = "start" })
for _, plugin in pairs(Config.plugins) do
if plugin.lazy == false and not plugin._.loaded then
M.load(plugin, { start = "start" })
end
end
Util.track()
-- 3. load plugins from rtp, excluding after
Util.track({ start = "rtp plugins" })
for _, path in ipairs(rtp) do
if not path:find("after/?$") then
M.packadd(path)
end
end
Util.track()
-- 4. load after plugins
Util.track({ start = "after" })
for _, path in ipairs(vim.opt.rtp:get()) do
if path:find("after/?$") then
M.source_runtime(path, "plugin")
end
end
Util.track()
M.init_done = true
Util.track() Util.track()
end end

View File

@ -18,7 +18,7 @@ local M = {}
---@class LazyPluginHooks ---@class LazyPluginHooks
---@field init? fun(LazyPlugin) Will always be run ---@field init? fun(LazyPlugin) Will always be run
---@field config? fun(LazyPlugin) Will be executed when loading the plugin ---@field config? fun(LazyPlugin)|true|table Will be executed when loading the plugin
---@field build? string|fun(LazyPlugin) ---@field build? string|fun(LazyPlugin)
---@class LazyPluginHandlers: table<LazyHandlerTypes, string|string[]> ---@class LazyPluginHandlers: table<LazyHandlerTypes, string|string[]>