Skip to content

Commit

Permalink
fix(loader): source rtp /plugin files after loading start plugins. …
Browse files Browse the repository at this point in the history
…Fixes
  • Loading branch information
folke committed Dec 21, 2022
1 parent b802729 commit ff24f49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,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 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 plugins' `/after/plugin` files are sourced
4. all `/after/plugin` files from the original rtp are sourced
5. all the plugins' `init()` functions are executed
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

Files from runtime directories are always sourced in alphabetical order.

Expand Down
26 changes: 15 additions & 11 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@ end
function M.startup()
Util.track({ start = "startup" })

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

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

-- load start plugin
-- 1. load start plugin
Util.track({ start = "start" })
for _, plugin in pairs(Config.plugins) do
if plugin.lazy == false then
Expand All @@ -66,7 +61,16 @@ function M.startup()
end
Util.track()

-- load after plugins
-- 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
Expand All @@ -77,7 +81,7 @@ function M.startup()

M.init_done = true

-- run plugin init
-- 4. run plugin init
Util.track({ start = "init" })
for _, plugin in pairs(Config.plugins) do
if plugin.init then
Expand Down

0 comments on commit ff24f49

Please sign in to comment.