Skip to content

Commit 93d3072

Browse files
committed
fix: add plugin after dir to rtp for start plugins so it gets picked up during startup
1 parent ccc506d commit 93d3072

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

lua/lazy/core/loader.lua

+23-10
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,23 @@ end
3737

3838
function M.init_plugins()
3939
Util.track("loader")
40+
4041
Util.track({ start = "init" })
4142
for _, plugin in pairs(Config.plugins) do
43+
-- run plugin init
4244
if plugin.init then
4345
Util.track({ plugin = plugin.name, init = "init" })
4446
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
4547
Util.track()
4648
end
49+
50+
-- load start plugin
4751
if plugin.lazy == false then
4852
M.load(plugin, { start = "startup" })
4953
end
5054
end
5155
Util.track()
56+
5257
Util.track()
5358
M.init_done = true
5459
end
@@ -82,6 +87,15 @@ function M.load(plugins, reason)
8287
Util.track({ plugin = plugin.name, start = reason.start })
8388

8489
vim.opt.runtimepath:prepend(plugin.dir)
90+
if not M.init_done then
91+
local after = plugin.dir .. "/after"
92+
-- only add the after directories during startup
93+
-- afterwards we only source the runtime files in after
94+
-- Check if it exists here, to prevent further rtp file checks during startup
95+
if vim.loop.fs_stat(after) then
96+
vim.opt.runtimepath:append(after)
97+
end
98+
end
8599

86100
if plugin.dependencies then
87101
M.load(plugin.dependencies, {})
@@ -102,24 +116,23 @@ function M.load(plugins, reason)
102116
end
103117

104118
---@param plugin LazyPlugin
105-
---@param force? boolean
106-
function M.packadd(plugin, force)
119+
function M.packadd(plugin)
107120
-- FIXME: investigate further what else is needed
108121
-- vim.cmd.packadd(plugin.name)
109122
-- M.source_runtime(plugin, "/after/plugin")
110-
if M.init_done or force then
111-
M.source_runtime(plugin, "/plugin")
123+
if M.init_done then
124+
M.source_runtime(plugin.dir, "/plugin")
112125
if vim.g.did_load_filetypes == 1 then
113-
M.source_runtime(plugin, "/ftdetect")
126+
M.source_runtime(plugin.dir, "/ftdetect")
114127
end
115-
M.source_runtime(plugin, "/after/plugin")
128+
M.source_runtime(plugin.dir, "/after/plugin")
116129
end
117130
end
118131

119-
---@param plugin LazyPlugin
120-
---@param dir? string
121-
function M.source_runtime(plugin, dir)
122-
Util.walk(plugin.dir .. dir, function(path, _, t)
132+
---@param ... string
133+
function M.source_runtime(...)
134+
local dir = table.concat({ ... }, "/")
135+
Util.walk(dir, function(path, _, t)
123136
local ext = path:sub(-3)
124137
if t == "file" and (ext == "lua" or ext == "vim") then
125138
vim.cmd("silent source " .. path)

0 commit comments

Comments
 (0)