mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
feat(plugin): dont include plugin spec fragments for disabled or optional plugins (#1058)
* feat(plugin): dont include plugin spec fragments for disabled or optional plugins * test: fixed tests * fix(plugin): calculate handlers after disabling plugins * fix(plugin): clear Plugin._.super when rebuilding * fix(ui): dont process handlers for disabled plugins * test: added tests for disabling fragments * fix(plugin): ignore any installed deps of a disabled conditional plugin. Fixes #1053
This commit is contained in:
parent
6b55e4695a
commit
f3c7169dd6
4 changed files with 181 additions and 80 deletions
|
@ -1,11 +1,25 @@
|
|||
local Config = require("lazy.core.config")
|
||||
local Plugin = require("lazy.core.plugin")
|
||||
local Loader = require("lazy.core.loader")
|
||||
|
||||
local assert = require("luassert")
|
||||
|
||||
Config.setup()
|
||||
|
||||
---@param plugins LazyPlugin[]|LazyPlugin
|
||||
local function clean(plugins)
|
||||
local p = plugins
|
||||
plugins = type(plugins) == "table" and plugins or { plugins }
|
||||
for _, plugin in pairs(plugins) do
|
||||
plugin._.fid = nil
|
||||
plugin._.fpid = nil
|
||||
plugin._.fdeps = nil
|
||||
if plugin._.dep == false then
|
||||
plugin._.dep = nil
|
||||
end
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
describe("plugin spec url/name", function()
|
||||
local tests = {
|
||||
{ { dir = "~/foo" }, { name = "foo", dir = vim.fn.fnamemodify("~/foo", ":p") } },
|
||||
|
@ -28,6 +42,7 @@ describe("plugin spec url/name", function()
|
|||
end
|
||||
local spec = Plugin.Spec.new(test[1])
|
||||
local plugins = vim.tbl_values(spec.plugins)
|
||||
plugins[1]._ = {}
|
||||
assert(#spec.notifs == 0)
|
||||
assert.equal(1, #plugins)
|
||||
assert.same(test[2], plugins[1])
|
||||
|
@ -61,7 +76,7 @@ describe("plugin spec opt", function()
|
|||
for _, plugin in pairs(spec.plugins) do
|
||||
plugin.dir = nil
|
||||
end
|
||||
assert.same(spec.plugins, {
|
||||
assert.same(clean(spec.plugins), {
|
||||
bar = {
|
||||
"foo/bar",
|
||||
_ = {},
|
||||
|
@ -105,7 +120,7 @@ describe("plugin spec opt", function()
|
|||
for _, plugin in pairs(spec.plugins) do
|
||||
plugin.dir = nil
|
||||
end
|
||||
assert.same(spec.plugins, {
|
||||
assert.same(clean(spec.plugins), {
|
||||
bar = {
|
||||
"foo/bar",
|
||||
_ = {},
|
||||
|
@ -335,3 +350,32 @@ describe("plugin opts", function()
|
|||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("plugin spec", function()
|
||||
it("only includes fragments from enabled plugins", function()
|
||||
local tests = {
|
||||
{
|
||||
spec = {
|
||||
{ "foo/disabled", enabled = false, dependencies = { "foo/bar", opts = { key_disabled = true } } },
|
||||
{ "foo/disabled", dependencies = { "foo/bar", opts = { key_disabled_two = true } } },
|
||||
{ "foo/conditional", cond = false, dependencies = { "foo/bar", opts = { key_cond = true } } },
|
||||
{ "foo/optional", optional = true, dependencies = { "foo/bar", opts = { key_optional = true } } },
|
||||
{ "foo/active", dependencies = { "foo/bar", opts = { key_active = true } } },
|
||||
{
|
||||
"foo/bar",
|
||||
opts = { key = true },
|
||||
},
|
||||
},
|
||||
expected_opts = { key = true, key_active = true },
|
||||
}, -- for now, one test...
|
||||
}
|
||||
for _, test in ipairs(tests) do
|
||||
local spec = Plugin.Spec.new(test.spec)
|
||||
assert(#spec.notifs == 0)
|
||||
assert(vim.tbl_count(spec.plugins) == 2)
|
||||
assert(spec.plugins.active)
|
||||
assert(spec.plugins.bar)
|
||||
assert.same(test.expected_opts, Plugin.values(spec.plugins.bar, "opts"))
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue