fix: add plugin after dir to rtp for start plugins so it gets picked up during startup

This commit is contained in:
Folke Lemaitre 2022-12-03 17:43:55 +01:00
parent ccc506d5f7
commit 93d30722a0
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 23 additions and 10 deletions

View File

@ -37,18 +37,23 @@ end
function M.init_plugins() function M.init_plugins()
Util.track("loader") Util.track("loader")
Util.track({ start = "init" }) Util.track({ start = "init" })
for _, plugin in pairs(Config.plugins) do for _, plugin in pairs(Config.plugins) do
-- run plugin init
if plugin.init then if plugin.init then
Util.track({ plugin = plugin.name, init = "init" }) Util.track({ plugin = plugin.name, init = "init" })
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**") Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
Util.track() Util.track()
end end
-- load start plugin
if plugin.lazy == false then if plugin.lazy == false then
M.load(plugin, { start = "startup" }) M.load(plugin, { start = "startup" })
end end
end end
Util.track() Util.track()
Util.track() Util.track()
M.init_done = true M.init_done = true
end end
@ -82,6 +87,15 @@ function M.load(plugins, reason)
Util.track({ plugin = plugin.name, start = reason.start }) Util.track({ plugin = plugin.name, start = reason.start })
vim.opt.runtimepath:prepend(plugin.dir) vim.opt.runtimepath:prepend(plugin.dir)
if not M.init_done then
local after = plugin.dir .. "/after"
-- only add the after directories during startup
-- afterwards we only source the runtime files in after
-- Check if it exists here, to prevent further rtp file checks during startup
if vim.loop.fs_stat(after) then
vim.opt.runtimepath:append(after)
end
end
if plugin.dependencies then if plugin.dependencies then
M.load(plugin.dependencies, {}) M.load(plugin.dependencies, {})
@ -102,24 +116,23 @@ function M.load(plugins, reason)
end end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
---@param force? boolean function M.packadd(plugin)
function M.packadd(plugin, force)
-- FIXME: investigate further what else is needed -- FIXME: investigate further what else is needed
-- vim.cmd.packadd(plugin.name) -- vim.cmd.packadd(plugin.name)
-- M.source_runtime(plugin, "/after/plugin") -- M.source_runtime(plugin, "/after/plugin")
if M.init_done or force then if M.init_done then
M.source_runtime(plugin, "/plugin") M.source_runtime(plugin.dir, "/plugin")
if vim.g.did_load_filetypes == 1 then if vim.g.did_load_filetypes == 1 then
M.source_runtime(plugin, "/ftdetect") M.source_runtime(plugin.dir, "/ftdetect")
end end
M.source_runtime(plugin, "/after/plugin") M.source_runtime(plugin.dir, "/after/plugin")
end end
end end
---@param plugin LazyPlugin ---@param ... string
---@param dir? string function M.source_runtime(...)
function M.source_runtime(plugin, dir) local dir = table.concat({ ... }, "/")
Util.walk(plugin.dir .. dir, function(path, _, t) Util.walk(dir, function(path, _, t)
local ext = path:sub(-3) local ext = path:sub(-3)
if t == "file" and (ext == "lua" or ext == "vim") then if t == "file" and (ext == "lua" or ext == "vim") then
vim.cmd("silent source " .. path) vim.cmd("silent source " .. path)