feat(plugin): dev.path can now be a function (#1157)

In some case, `dev.path .. plugin.name` is not enoguh.

For example, when using `ghq` to manage projects, plugin directories may
vary by onewrs of the plugins.

With this change, users can do something like below

``` lua
require("lazy").setup("plugins", {
  dev = {
    path = function(p)
      -- ghq
      local path, cnt = string.gsub(p.url, "^https://(.*)%.git$", "~/ghq/%1")
      if cnt == 1 then
        return path
      end

      -- fallback to default
      return "~/projects/" .. plugin.name
    end,
  },
})
```
This commit is contained in:
atusy 2024-01-20 22:19:09 +09:00 committed by GitHub
parent 42694c4fda
commit a6f782adc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 8 deletions

View file

@ -106,11 +106,16 @@ function Spec:add(plugin, results)
end
-- dev plugins
if
plugin.dev
and (not Config.options.dev.fallback or vim.fn.isdirectory(Config.options.dev.path .. "/" .. plugin.name) == 1)
then
dir = Config.options.dev.path .. "/" .. plugin.name
if plugin.dev then
local dir_dev
if type(Config.options.dev.path) == "string" then
dir_dev = Config.options.dev.path .. "/" .. plugin.name
else
dir_dev = Util.norm(Config.options.dev.path(plugin))
end
if not Config.options.dev.fallback or vim.fn.isdirectory(dir_dev) == 1 then
dir = dir_dev
end
elseif plugin.dev == false then
-- explicitely select the default path
dir = Config.options.root .. "/" .. plugin.name