Skip to content

Commit

Permalink
fix!: run init() before loading start plugins. Fixes #107
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 22, 2022
1 parent fb8287c commit 2756a6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

1. all plugins with `lazy=false` are loaded. This includes sourcing `/plugin` and `/ftdetect` files. (`/after` will not be sourced yet)
2. all files from `/plugin` and `/ftdetect` directories in you rtp are sourced (excluding `/after`)
3. all `/after/plugin` files are sourced (this inludes `/after` from plugins)
4. all the plugins' `init()` functions are executed
1. all the plugins' `init()` functions are executed
2. all plugins with `lazy=false` are loaded. This includes sourcing `/plugin` and `/ftdetect` files. (`/after` will not be sourced yet)
3. all files from `/plugin` and `/ftdetect` directories in you rtp are sourced (excluding `/after`)
4. all `/after/plugin` files are sourced (this inludes `/after` from plugins)

Files from runtime directories are always sourced in alphabetical order.

Expand Down
30 changes: 15 additions & 15 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,27 @@ function M.startup()
-- backup original rtp
local rtp = vim.opt.rtp:get()

-- 1. load start plugin
-- 1. run plugin init
Util.track({ start = "init" })
for _, plugin in pairs(Config.plugins) do
if plugin.init then
Util.track({ plugin = plugin.name, init = "init" })
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
Util.track()
end
end
Util.track()

-- 2. load start plugin
Util.track({ start = "start" })
for _, plugin in pairs(Config.plugins) do
if plugin.lazy == false then
if plugin.lazy == false and not plugin._.loaded then
M.load(plugin, { start = "start" })
end
end
Util.track()

-- 2. load plugins from rtp, excluding after
-- 3. load plugins from rtp, excluding after
Util.track({ start = "rtp plugins" })
for _, path in ipairs(rtp) do
if not path:find("after/?$") then
Expand All @@ -76,7 +87,7 @@ function M.startup()
end
Util.track()

-- 3. load after plugins
-- 4. load after plugins
Util.track({ start = "after" })
for _, path in ipairs(vim.opt.rtp:get()) do
if path:find("after/?$") then
Expand All @@ -87,17 +98,6 @@ function M.startup()

M.init_done = true

-- 4. run plugin init
Util.track({ start = "init" })
for _, plugin in pairs(Config.plugins) do
if plugin.init then
Util.track({ plugin = plugin.name, init = "init" })
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
Util.track()
end
end
Util.track()

Util.track()
end

Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local M = {}

---@class LazyPluginHooks
---@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)

---@class LazyPluginHandlers: table<LazyHandlerTypes, string|string[]>
Expand Down

0 comments on commit 2756a6f

Please sign in to comment.