diff --git a/README.md b/README.md index ebcca6a..fef589c 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,8 @@ return { dev = { -- directory where you store your local plugin projects path = "~/projects", + ---@type string[] | nil you may include a list of local paths to also check + extra_paths = nil, ---@type string[] plugins that match these patterns will use your local versions instead of being fetched from GitHub patterns = {}, -- For example {"folke"} fallback = false, -- Fallback to git when local plugin doesn't exist @@ -424,7 +426,7 @@ return { rtp = { reset = true, -- reset the runtime path to $VIMRUNTIME and your config directory ---@type string[] - paths = {}, -- add any custom paths here that you want to includes in the rtp + paths = {}, -- add any custom paths here that you want to append to the rtp ---@type string[] list any plugins you want to disable here disabled_plugins = { -- "gzip", @@ -436,6 +438,18 @@ return { -- "tutor", -- "zipPlugin", }, + -- for niche situations where lazy breaks oddly built configurations + -- such as those that can be produced via nix. + ---@type fun(DEFAULT: string[], ME: string, VIMRUNTIME: string, NVIM_LIB: string): string[] + override_base_rtp = function(DEFAULT, ME, VIMRUNTIME, NVIM_LIB) return DEFAULT end + -- DEFAULT = { + -- vim.fn.stdpath("config"), + -- vim.fn.stdpath("data") .. "/site", + -- ME, + -- VIMRUNTIME, + -- NVIM_LIB, + -- vim.fn.stdpath("config") .. "/after", + -- } }, }, -- lazy can generate helptags from the headings in markdown readme files, diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index 1fbf3ef..66c28c4 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -32,6 +32,8 @@ M.defaults = { dev = { -- directory where you store your local plugin projects path = "~/projects", + ---@type string[] | nil you may include a list of local paths to also check + extra_paths = nil, ---@type string[] plugins that match these patterns will use your local versions instead of being fetched from GitHub patterns = {}, -- For example {"folke"} fallback = false, -- Fallback to git when local plugin doesn't exist @@ -134,7 +136,7 @@ M.defaults = { rtp = { reset = true, -- reset the runtime path to $VIMRUNTIME and your config directory ---@type string[] - paths = {}, -- add any custom paths here that you want to includes in the rtp + paths = {}, -- add any custom paths here that you want to append to the rtp ---@type string[] list any plugins you want to disable here disabled_plugins = { -- "gzip", @@ -146,6 +148,18 @@ M.defaults = { -- "tutor", -- "zipPlugin", }, + -- for niche situations where lazy breaks oddly built configurations + -- such as those that can be produced via nix. + ---@type fun(DEFAULT: string[], ME: string, VIMRUNTIME: string, NVIM_LIB: string): string[] + override_base_rtp = function(DEFAULT, ME, VIMRUNTIME, NVIM_LIB) return DEFAULT end + -- DEFAULT = { + -- vim.fn.stdpath("config"), + -- vim.fn.stdpath("data") .. "/site", + -- ME, + -- VIMRUNTIME, + -- NVIM_LIB, + -- vim.fn.stdpath("config") .. "/after", + -- } }, }, -- lazy can generate helptags from the headings in markdown readme files, @@ -212,6 +226,7 @@ function M.setup(opts) end table.insert(M.options.install.colorscheme, "habamax") + M.options.dev.extra_paths = Util.norm_list(M.options.dev.extra_paths) M.options.root = Util.norm(M.options.root) M.options.dev.path = Util.norm(M.options.dev.path) M.options.lockfile = Util.norm(M.options.lockfile) @@ -226,14 +241,16 @@ function M.setup(opts) M.me = debug.getinfo(1, "S").source:sub(2) M.me = Util.norm(vim.fn.fnamemodify(M.me, ":p:h:h:h:h")) if M.options.performance.rtp.reset then - vim.opt.rtp = { + local NVIM_LIB = vim.fn.fnamemodify(vim.v.progpath, ":p:h:h") .. "/lib/nvim" + local base_rtp = { vim.fn.stdpath("config"), vim.fn.stdpath("data") .. "/site", M.me, vim.env.VIMRUNTIME, - vim.fn.fnamemodify(vim.v.progpath, ":p:h:h") .. "/lib/nvim", + NVIM_LIB, vim.fn.stdpath("config") .. "/after", } + vim.opt.rtp = M.options.performance.rtp.override_base_rtp(base_rtp, M.me, vim.env.VIMRUNTIME, NVIM_LIB) end for _, path in ipairs(M.options.performance.rtp.paths) do vim.opt.rtp:append(path) diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index fc25f8d..6fac979 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -106,11 +106,31 @@ function Spec:add(plugin, results) end -- dev plugins + local devPath = nil + + -- check dev.path, and if not check dev.extra_paths + -- if not found, devPath will remain nil + if plugin.dev then + if vim.fn.isdirectory(Config.options.dev.path .. "/" .. plugin.name) == 1 then + devPath = Config.options.dev.path .. "/" .. plugin.name + elseif Config.options.dev.extra_paths + and type(Config.options.dev.extra_paths) == 'table' + then + for _, path in ipairs(Config.options.dev.extra_paths) do + if vim.fn.isdirectory(path .. "/" .. plugin.name) == 1 then + devPath = path .. "/" .. plugin.name + break + end + end + end + end + + -- if dev, add dev path as plugin dir, otherwise use root if plugin.dev - and (not Config.options.dev.fallback or vim.fn.isdirectory(Config.options.dev.path .. "/" .. plugin.name) == 1) + and (not Config.options.dev.fallback or devPath) then - dir = Config.options.dev.path .. "/" .. plugin.name + dir = devPath elseif plugin.dev == false then -- explicitely select the default path dir = Config.options.root .. "/" .. plugin.name diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index 77cb8f5..f72f664 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -64,6 +64,19 @@ function M.norm(path) return path:sub(-1) == "/" and path:sub(1, -2) or path end +---@return table | nil +function M.norm_list(list) + if M.is_list(list) then + local normalized_paths = {} + for k, path in ipairs(list) do + table.insert(normalized_paths, k, M.norm(path)) + end + return normalized_paths + else + return nil + end +end + ---@param opts? {level?: number} function M.pretty_trace(opts) opts = opts or {}