Skip to content

Commit ff24f49

Browse files
committed
fix(loader): source rtp /plugin files after loading start plugins. Fixes
1 parent b802729 commit ff24f49

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,10 @@ startup sequence for more flexibility and better performance.
463463

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

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

472471
Files from runtime directories are always sourced in alphabetical order.
473472

lua/lazy/core/loader.lua

+15-11
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,13 @@ end
4646
function M.startup()
4747
Util.track({ start = "startup" })
4848

49+
-- load filetype.lua first since plugins might depend on that
4950
M.source(vim.env.VIMRUNTIME .. "/filetype.lua")
5051

51-
-- load plugins from rtp, excluding after
52-
Util.track({ start = "rtp plugins" })
53-
for _, path in ipairs(vim.opt.rtp:get()) do
54-
if not path:find("after/?$") then
55-
M.packadd(path)
56-
end
57-
end
58-
Util.track()
52+
-- backup original rtp
53+
local rtp = vim.opt.rtp:get()
5954

60-
-- load start plugin
55+
-- 1. load start plugin
6156
Util.track({ start = "start" })
6257
for _, plugin in pairs(Config.plugins) do
6358
if plugin.lazy == false then
@@ -66,7 +61,16 @@ function M.startup()
6661
end
6762
Util.track()
6863

69-
-- load after plugins
64+
-- 2. load plugins from rtp, excluding after
65+
Util.track({ start = "rtp plugins" })
66+
for _, path in ipairs(rtp) do
67+
if not path:find("after/?$") then
68+
M.packadd(path)
69+
end
70+
end
71+
Util.track()
72+
73+
-- 3. load after plugins
7074
Util.track({ start = "after" })
7175
for _, path in ipairs(vim.opt.rtp:get()) do
7276
if path:find("after/?$") then
@@ -77,7 +81,7 @@ function M.startup()
7781

7882
M.init_done = true
7983

80-
-- run plugin init
84+
-- 4. run plugin init
8185
Util.track({ start = "init" })
8286
for _, plugin in pairs(Config.plugins) do
8387
if plugin.init then

0 commit comments

Comments
 (0)