From 3606d62918c8ddc92f801c2bb9a2a362c9348cd2 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 20 Dec 2022 23:35:06 +0100 Subject: [PATCH] fix: add after directories to rtp to make after/ftplugin and others work. Fixes #47 --- lua/lazy/core/cache.lua | 2 +- lua/lazy/core/loader.lua | 40 +++++++++++++++++----------------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index a57dabb..81d85f6 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -179,7 +179,7 @@ function M.get_rtp() end for _, path in ipairs(vim.api.nvim_list_runtime_paths()) do path = path:gsub("\\", "/") - if not skip[path] then + if not skip[path] and not path:find("after/?$") then M.rtp[#M.rtp + 1] = path end end diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index 8a4a7fd..f705f7c 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -46,18 +46,11 @@ end function M.startup() Util.track({ start = "startup" }) - local rtp = vim.opt.rtp:get() - - Util.track({ start = "filetype" }) - local ft = vim.env.VIMRUNTIME .. "/filetype.lua" - Util.try(function() - vim.cmd("silent source " .. ft) - end, "Failed to source `" .. ft .. "`") - Util.track() + M.source(vim.env.VIMRUNTIME .. "/filetype.lua") -- load plugins from rtp, excluding after Util.track({ start = "rtp plugins" }) - for _, path in ipairs(rtp) do + for _, path in ipairs(vim.opt.rtp:get()) do if not path:find("after/?$") then M.packadd(path) end @@ -73,16 +66,9 @@ function M.startup() end Util.track() - -- load after files + -- load after plugins Util.track({ start = "after" }) - -- load after files from plugins - for _, plugin in pairs(Config.plugins) do - if plugin._.loaded then - M.source_runtime(plugin.dir, "after/plugin") - end - end - -- load after files from rtp plugins - for _, path in ipairs(rtp) do + for _, path in ipairs(vim.opt.rtp:get()) do if path:find("after/?$") then M.source_runtime(path, "plugin") end @@ -135,6 +121,10 @@ function M.load(plugins, reason) Handler.disable(plugin) vim.opt.runtimepath:prepend(plugin.dir) + local after = plugin.dir .. "/after" + if vim.loop.fs_stat(after) then + vim.opt.runtimepath:append(after) + end if plugin.dependencies then M.load(plugin.dependencies, {}) @@ -185,14 +175,18 @@ function M.source_runtime(...) -- plugin files are sourced alphabetically per directory table.sort(files) for _, path in ipairs(files) do - Util.track({ runtime = path }) - Util.try(function() - vim.cmd("silent source " .. path) - end, "Failed to source `" .. path .. "`") - Util.track() + M.source(path) end end +function M.source(path) + Util.track({ runtime = path }) + Util.try(function() + vim.cmd("silent source " .. path) + end, "Failed to source `" .. path .. "`") + Util.track() +end + -- This loader is added as the very last one. -- This only hits when the modname is not cached and -- even then only once per plugin. So pretty much never.