mirror of https://github.com/folke/lazy.nvim.git
feat: lazy handler implies opt=true
This commit is contained in:
parent
54526e062a
commit
b796abcc33
|
@ -41,7 +41,7 @@
|
||||||
- [x] rename requires to dependencies
|
- [x] rename requires to dependencies
|
||||||
- [x] move tasks etc to Plugin.state
|
- [x] move tasks etc to Plugin.state
|
||||||
- [ ] allow setting up plugins through config
|
- [ ] allow setting up plugins through config
|
||||||
- [ ] handlers imply opt
|
- [x] handlers imply opt
|
||||||
- [x] dependencies imply opt for deps
|
- [x] dependencies imply opt for deps
|
||||||
- [x] fix local plugin spec
|
- [x] fix local plugin spec
|
||||||
- [ ] investigate all opt=true. Simplifies logic (easily switch between opt/start afterwards)
|
- [ ] investigate all opt=true. Simplifies logic (easily switch between opt/start afterwards)
|
||||||
|
|
|
@ -2,6 +2,7 @@ local Config = require("lazy.core.config")
|
||||||
local Util = require("lazy.core.util")
|
local Util = require("lazy.core.util")
|
||||||
local Module = require("lazy.core.module")
|
local Module = require("lazy.core.module")
|
||||||
local Cache = require("lazy.core.cache")
|
local Cache = require("lazy.core.cache")
|
||||||
|
local Handler = require("lazy.core.handler")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
@ -163,7 +164,6 @@ end
|
||||||
function M.merge(old, new)
|
function M.merge(old, new)
|
||||||
local is_dep = old.dep and new.dep
|
local is_dep = old.dep and new.dep
|
||||||
|
|
||||||
local Handler = require("lazy.core.handler")
|
|
||||||
---@diagnostic disable-next-line: no-unknown
|
---@diagnostic disable-next-line: no-unknown
|
||||||
for k, v in pairs(new) do
|
for k, v in pairs(new) do
|
||||||
if k == "dep" then
|
if k == "dep" then
|
||||||
|
@ -205,7 +205,14 @@ function M.update_state(opts)
|
||||||
plugin._ = plugin._ or {}
|
plugin._ = plugin._ or {}
|
||||||
plugin[1] = plugin["1"] or plugin[1]
|
plugin[1] = plugin["1"] or plugin[1]
|
||||||
if plugin.opt == nil then
|
if plugin.opt == nil then
|
||||||
plugin.opt = plugin.dep or Config.options.opt
|
local has_handler = false
|
||||||
|
for handler, _ in pairs(Handler.handlers) do
|
||||||
|
if plugin[handler] then
|
||||||
|
has_handler = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
plugin.opt = plugin.dep or has_handler or Config.options.opt
|
||||||
end
|
end
|
||||||
local opt = plugin.opt and "opt" or "start"
|
local opt = plugin.opt and "opt" or "start"
|
||||||
plugin.dir = Config.options.packpath .. "/" .. opt .. "/" .. plugin.name
|
plugin.dir = Config.options.packpath .. "/" .. opt .. "/" .. plugin.name
|
||||||
|
|
|
@ -63,6 +63,15 @@ describe("plugin spec opt", function()
|
||||||
assert(spec.plugins.dep1.opt == false)
|
assert(spec.plugins.dep1.opt == false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("handles opt from dep", function()
|
||||||
|
Config.options.opt = false
|
||||||
|
local spec = Plugin.Spec.new({ "foo/bar", module = "foo" })
|
||||||
|
Plugin.update_state({ plugins = spec.plugins })
|
||||||
|
assert.same(1, vim.tbl_count(spec.plugins))
|
||||||
|
assert(spec.plugins.bar.dep ~= true)
|
||||||
|
assert(spec.plugins.bar.opt == true)
|
||||||
|
end)
|
||||||
|
|
||||||
it("merges lazy loaders", function()
|
it("merges lazy loaders", function()
|
||||||
local tests = {
|
local tests = {
|
||||||
{ { "foo/bar", module = "mod1" }, { "foo/bar", module = "mod2" } },
|
{ { "foo/bar", module = "mod1" }, { "foo/bar", module = "mod2" } },
|
||||||
|
|
Loading…
Reference in New Issue