mirror of https://github.com/folke/lazy.nvim.git
fix(plugin): improved dir/dev merging. Fixes #993
This commit is contained in:
parent
0c53d4673f
commit
3dc413d6fd
|
@ -84,8 +84,11 @@ function Spec:add(plugin, results)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@type string?
|
||||||
|
local dir
|
||||||
|
|
||||||
if plugin.dir then
|
if plugin.dir then
|
||||||
plugin.dir = Util.norm(plugin.dir)
|
dir = Util.norm(plugin.dir)
|
||||||
-- local plugin
|
-- local plugin
|
||||||
plugin.name = plugin.name or Spec.get_name(plugin.dir)
|
plugin.name = plugin.name or Spec.get_name(plugin.dir)
|
||||||
elseif plugin.url then
|
elseif plugin.url then
|
||||||
|
@ -99,16 +102,6 @@ function Spec:add(plugin, results)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- dev plugins
|
|
||||||
if
|
|
||||||
plugin.dev
|
|
||||||
and (not Config.options.dev.fallback or vim.fn.isdirectory(Config.options.dev.path .. "/" .. plugin.name) == 1)
|
|
||||||
then
|
|
||||||
plugin.dir = Config.options.dev.path .. "/" .. plugin.name
|
|
||||||
else
|
|
||||||
-- remote plugin
|
|
||||||
plugin.dir = Config.options.root .. "/" .. plugin.name
|
|
||||||
end
|
|
||||||
elseif is_ref then
|
elseif is_ref then
|
||||||
plugin.name = plugin[1]
|
plugin.name = plugin[1]
|
||||||
else
|
else
|
||||||
|
@ -121,6 +114,17 @@ function Spec:add(plugin, results)
|
||||||
return
|
return
|
||||||
end
|
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
|
||||||
|
elseif plugin.dev == false then
|
||||||
|
-- explicitely select the default path
|
||||||
|
dir = Config.options.root .. "/" .. plugin.name
|
||||||
|
end
|
||||||
|
|
||||||
if type(plugin.config) == "table" then
|
if type(plugin.config) == "table" then
|
||||||
self:warn(
|
self:warn(
|
||||||
"{" .. plugin.name .. "}: setting a table to `Plugin.config` is deprecated. Please use `Plugin.opts` instead"
|
"{" .. plugin.name .. "}: setting a table to `Plugin.config` is deprecated. Please use `Plugin.opts` instead"
|
||||||
|
@ -134,12 +138,15 @@ function Spec:add(plugin, results)
|
||||||
|
|
||||||
M.last_fid = M.last_fid + 1
|
M.last_fid = M.last_fid + 1
|
||||||
plugin._ = {
|
plugin._ = {
|
||||||
|
dir = dir,
|
||||||
fid = M.last_fid,
|
fid = M.last_fid,
|
||||||
fpid = fpid,
|
fpid = fpid,
|
||||||
dep = fpid ~= nil,
|
dep = fpid ~= nil,
|
||||||
module = self.importing,
|
module = self.importing,
|
||||||
}
|
}
|
||||||
self.fragments[plugin._.fid] = plugin
|
self.fragments[plugin._.fid] = plugin
|
||||||
|
-- remote plugin
|
||||||
|
plugin.dir = plugin._.dir or (plugin.name and (Config.options.root .. "/" .. plugin.name)) or nil
|
||||||
|
|
||||||
if fpid then
|
if fpid then
|
||||||
local parent = self.fragments[fpid]
|
local parent = self.fragments[fpid]
|
||||||
|
@ -328,11 +335,14 @@ end
|
||||||
|
|
||||||
function Spec:report(level)
|
function Spec:report(level)
|
||||||
level = level or vim.log.levels.ERROR
|
level = level or vim.log.levels.ERROR
|
||||||
|
local count = 0
|
||||||
for _, notif in ipairs(self.notifs) do
|
for _, notif in ipairs(self.notifs) do
|
||||||
if notif.level >= level then
|
if notif.level >= level then
|
||||||
Util.notify(notif.msg, { level = notif.level })
|
Util.notify(notif.msg, { level = notif.level })
|
||||||
|
count = count + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param spec LazySpec|LazySpecImport
|
---@param spec LazySpec|LazySpecImport
|
||||||
|
@ -448,6 +458,12 @@ function Spec:merge(old, new)
|
||||||
Util.extend(new.dependencies, old.dependencies)
|
Util.extend(new.dependencies, old.dependencies)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local new_dir = new._.dir or old._.dir or (new.name and (Config.options.root .. "/" .. new.name)) or nil
|
||||||
|
if new_dir ~= new.dir then
|
||||||
|
self:warn("Plugin `" .. new.name .. "` changed `dir`:\n- from: `" .. new.dir .. "`\n- to: `" .. new_dir .. "`")
|
||||||
|
end
|
||||||
|
new.dir = new_dir
|
||||||
|
|
||||||
new._.super = old
|
new._.super = old
|
||||||
setmetatable(new, { __index = old })
|
setmetatable(new, { __index = old })
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
---@field cond? boolean
|
---@field cond? boolean
|
||||||
---@field super? LazyPlugin
|
---@field super? LazyPlugin
|
||||||
---@field module? string
|
---@field module? string
|
||||||
|
---@field dir? string Explicit dir or dev set for this plugin
|
||||||
|
|
||||||
---@alias PluginOpts table|fun(self:LazyPlugin, opts:table):table?
|
---@alias PluginOpts table|fun(self:LazyPlugin, opts:table):table?
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,43 @@ describe("plugin spec url/name", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("plugin spec dir", function()
|
||||||
|
local tests = {
|
||||||
|
{
|
||||||
|
"~/projects/gitsigns.nvim",
|
||||||
|
{ "lewis6991/gitsigns.nvim", opts = {}, dev = true },
|
||||||
|
{ "lewis6991/gitsigns.nvim" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"~/projects/gitsigns.nvim",
|
||||||
|
{ "lewis6991/gitsigns.nvim", opts = {}, dev = true },
|
||||||
|
{ "gitsigns.nvim" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"~/projects/gitsigns.nvim",
|
||||||
|
{ "lewis6991/gitsigns.nvim", opts = {} },
|
||||||
|
{ "lewis6991/gitsigns.nvim", dev = true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"~/projects/gitsigns.nvim",
|
||||||
|
{ "lewis6991/gitsigns.nvim", opts = {} },
|
||||||
|
{ "gitsigns.nvim", dev = true },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test in ipairs(tests) do
|
||||||
|
local dir = vim.fn.expand(test[1])
|
||||||
|
local input = vim.list_slice(test, 2)
|
||||||
|
it("parses dir " .. vim.inspect(input):gsub("%s+", " "), function()
|
||||||
|
local spec = Plugin.Spec.new(input)
|
||||||
|
local plugins = vim.tbl_values(spec.plugins)
|
||||||
|
assert(spec:report() == 0)
|
||||||
|
assert.equal(1, #plugins)
|
||||||
|
assert.same(dir, plugins[1].dir)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
describe("plugin spec opt", function()
|
describe("plugin spec opt", function()
|
||||||
it("handles dependencies", function()
|
it("handles dependencies", function()
|
||||||
Config.options.defaults.lazy = false
|
Config.options.defaults.lazy = false
|
||||||
|
|
Loading…
Reference in New Issue