Skip to content

Commit 2756a6f

Browse files
committed
fix!: run init() before loading start plugins. Fixes #107
1 parent fb8287c commit 2756a6f

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,10 @@ startup sequence for more flexibility and better performance.
511511

512512
In practice this means that step 10 of [Neovim Initialization](https://neovim.io/doc/user/starting.html#initialization) is done by Lazy:
513513

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

519519
Files from runtime directories are always sourced in alphabetical order.
520520

lua/lazy/core/loader.lua

+15-15
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,27 @@ function M.startup()
5858
-- backup original rtp
5959
local rtp = vim.opt.rtp:get()
6060

61-
-- 1. load start plugin
61+
-- 1. run plugin init
62+
Util.track({ start = "init" })
63+
for _, plugin in pairs(Config.plugins) do
64+
if plugin.init then
65+
Util.track({ plugin = plugin.name, init = "init" })
66+
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
67+
Util.track()
68+
end
69+
end
70+
Util.track()
71+
72+
-- 2. load start plugin
6273
Util.track({ start = "start" })
6374
for _, plugin in pairs(Config.plugins) do
64-
if plugin.lazy == false then
75+
if plugin.lazy == false and not plugin._.loaded then
6576
M.load(plugin, { start = "start" })
6677
end
6778
end
6879
Util.track()
6980

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

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

8899
M.init_done = true
89100

90-
-- 4. run plugin init
91-
Util.track({ start = "init" })
92-
for _, plugin in pairs(Config.plugins) do
93-
if plugin.init then
94-
Util.track({ plugin = plugin.name, init = "init" })
95-
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
96-
Util.track()
97-
end
98-
end
99-
Util.track()
100-
101101
Util.track()
102102
end
103103

lua/lazy/core/plugin.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local M = {}
1818

1919
---@class LazyPluginHooks
2020
---@field init? fun(LazyPlugin) Will always be run
21-
---@field config? fun(LazyPlugin) Will be executed when loading the plugin
21+
---@field config? fun(LazyPlugin)|true|table Will be executed when loading the plugin
2222
---@field build? string|fun(LazyPlugin)
2323

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

0 commit comments

Comments
 (0)