fix(loader): implemented correct adding to rtp. fix #230, fix #226

This commit is contained in:
Folke Lemaitre 2022-12-29 16:03:23 +01:00
parent c7122d64cd
commit 3a1a10cd75
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 34 additions and 8 deletions

View File

@ -182,8 +182,8 @@ function M.setup(spec, opts)
M.me = Util.norm(vim.fn.fnamemodify(M.me, ":p:h:h:h:h")) M.me = Util.norm(vim.fn.fnamemodify(M.me, ":p:h:h:h:h"))
if M.options.performance.rtp.reset then if M.options.performance.rtp.reset then
vim.opt.rtp = { vim.opt.rtp = {
M.me,
vim.fn.stdpath("config"), vim.fn.stdpath("config"),
M.me,
vim.env.VIMRUNTIME, vim.env.VIMRUNTIME,
vim.fn.fnamemodify(vim.v.progpath, ":p:h:h") .. "/lib/nvim", vim.fn.fnamemodify(vim.v.progpath, ":p:h:h") .. "/lib/nvim",
vim.fn.stdpath("config") .. "/after", vim.fn.stdpath("config") .. "/after",

View File

@ -80,7 +80,7 @@ function M.startup()
end end
Util.track() Util.track()
-- 3. load plugins from rtp, excluding after -- 3. load plugins from the original rtp, excluding after
Util.track({ start = "rtp plugins" }) Util.track({ start = "rtp plugins" })
for _, path in ipairs(rtp) do for _, path in ipairs(rtp) do
if not path:find("after/?$") then if not path:find("after/?$") then
@ -172,11 +172,7 @@ function M._load(plugin, reason)
Util.track({ plugin = plugin.name, start = reason.start }) Util.track({ plugin = plugin.name, start = reason.start })
Handler.disable(plugin) Handler.disable(plugin)
vim.opt.runtimepath:prepend(plugin.dir) M.add_to_rtp(plugin)
local after = plugin.dir .. "/after"
if vim.loop.fs_stat(after) then
vim.opt.runtimepath:append(after)
end
if plugin.dependencies then if plugin.dependencies then
Util.try(function() Util.try(function()
@ -271,6 +267,36 @@ function M.source_runtime(...)
end end
end end
-- This does the same as runtime.c:add_pack_dir_to_rtp
-- * find first after
-- * find lazy pack path
-- * insert right after lazy pack path or right before first after or at the end
-- * insert after dir right before first after or append to the end
---@param plugin LazyPlugin
function M.add_to_rtp(plugin)
local rtp = vim.api.nvim_get_runtime_file("", true)
local idx_dir, idx_after
for i, path in ipairs(rtp) do
if path == Config.me then
idx_dir = i + 1
elseif not idx_after and path:sub(-6, -1) == "/after" then
idx_after = i + 1 -- +1 to offset the insert of the plugin dir
idx_dir = idx_dir or i
break
end
end
table.insert(rtp, idx_dir or (#rtp + 1), plugin.dir)
local after = plugin.dir .. "/after"
if vim.loop.fs_stat(after) then
table.insert(rtp, idx_after or (#rtp + 1), after)
end
vim.opt.rtp = rtp
end
function M.source(path) function M.source(path)
Util.track({ runtime = path }) Util.track({ runtime = path })
Util.try(function() Util.try(function()

View File

@ -77,7 +77,7 @@ function M.bootstrap()
lazypath, lazypath,
}) })
end end
vim.opt.runtimepath:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
end end
---@return LazyPlugin[] ---@return LazyPlugin[]