From 68ef7cd3c291862858af084a23d664331aa431ce Mon Sep 17 00:00:00 2001 From: BirdeeHub Date: Mon, 8 Jan 2024 23:18:23 -0800 Subject: [PATCH] Added performance.rtp.custom_config_dir and dev.extra_paths for nix compatibility. Changes to be committed: modified: README.md modified: lua/lazy/core/config.lua modified: lua/lazy/core/plugin.lua --- README.md | 9 ++++++++- lua/lazy/core/config.lua | 22 +++++++++++++++++++--- lua/lazy/core/plugin.lua | 24 ++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ebcca6a..2b7459b 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,8 @@ return { dev = { -- directory where you store your local plugin projects path = "~/projects", + -- you may include a list of local paths to also check. e.g. { '~/projects1', '~/projects2' } + 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 include in the rtp ---@type string[] list any plugins you want to disable here disabled_plugins = { -- "gzip", @@ -436,6 +438,11 @@ return { -- "tutor", -- "zipPlugin", }, + -- custom_config_dir exists to work around circumstances + -- in which your config folder is not in the normal location, + -- and thus is unloaded when performance.rtp.reset = true + -- such as when loaded from the nix store + custom_config_dir = vim.fn.stdpath("config"), }, }, -- 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..74a13b6 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", + -- you may include a list of local paths to also check. e.g. { '~/projects1', '~/projects2' } + 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 include in the rtp ---@type string[] list any plugins you want to disable here disabled_plugins = { -- "gzip", @@ -146,6 +148,11 @@ M.defaults = { -- "tutor", -- "zipPlugin", }, + -- custom_config_dir exists to work around circumstances + -- in which your config folder is not in the normal location, + -- and thus is unloaded when performance.rtp.reset = true + -- such as when loaded from the nix store + custom_config_dir = vim.fn.stdpath("config"), }, }, -- lazy can generate helptags from the headings in markdown readme files, @@ -212,6 +219,14 @@ function M.setup(opts) end table.insert(M.options.install.colorscheme, "habamax") + -- normalize path options + if type(M.options.dev.extra_paths) == "table" then + local normalized_extra_dev_paths = {} + for k, path in ipairs(M.options.dev.extra_paths) do + table.insert(normalized_extra_dev_paths, k, Util.norm(path)) + end + M.options.dev.extra_paths = normalized_extra_dev_paths + end 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) @@ -225,14 +240,15 @@ 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")) + M.options.performance.rtp.custom_config_dir = Util.norm(M.options.performance.rtp.custom_config_dir) if M.options.performance.rtp.reset then vim.opt.rtp = { - vim.fn.stdpath("config"), + M.options.performance.rtp.custom_config_dir, vim.fn.stdpath("data") .. "/site", M.me, vim.env.VIMRUNTIME, vim.fn.fnamemodify(vim.v.progpath, ":p:h:h") .. "/lib/nvim", - vim.fn.stdpath("config") .. "/after", + M.options.performance.rtp.custom_config_dir .. "/after", } end for _, path in ipairs(M.options.performance.rtp.paths) do 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