mirror of https://github.com/folke/lazy.nvim.git
feat!: all plugins are now opt. Plugin.opt => Plugin.lazy
This commit is contained in:
parent
5e0662727d
commit
5134e797f3
|
@ -6,7 +6,7 @@ local M = {}
|
||||||
M.defaults = {
|
M.defaults = {
|
||||||
plugins = "config.plugins",
|
plugins = "config.plugins",
|
||||||
defaults = {
|
defaults = {
|
||||||
opt = false, -- should plugins default to "opt" or "start"
|
lazy = false, -- should plugins be loaded at startup?
|
||||||
version = nil,
|
version = nil,
|
||||||
-- version = "*", -- enable this to try installing the latest stable versions of plugins
|
-- version = "*", -- enable this to try installing the latest stable versions of plugins
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,6 +6,11 @@ local M = {}
|
||||||
---@type LazyPlugin[]
|
---@type LazyPlugin[]
|
||||||
M.loading = {}
|
M.loading = {}
|
||||||
|
|
||||||
|
function M.setup()
|
||||||
|
local Handler = require("lazy.core.handler")
|
||||||
|
Handler.setup()
|
||||||
|
end
|
||||||
|
|
||||||
function M.init_plugins()
|
function M.init_plugins()
|
||||||
Util.track("plugin_init")
|
Util.track("plugin_init")
|
||||||
for _, plugin in pairs(Config.plugins) do
|
for _, plugin in pairs(Config.plugins) do
|
||||||
|
@ -14,7 +19,7 @@ function M.init_plugins()
|
||||||
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
|
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
if plugin.opt == false then
|
if plugin.lazy == false then
|
||||||
M.load(plugin, { start = "start" })
|
M.load(plugin, { start = "start" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,8 +29,7 @@ end
|
||||||
---@class Loader
|
---@class Loader
|
||||||
---@param plugins string|LazyPlugin|string[]|LazyPlugin[]
|
---@param plugins string|LazyPlugin|string[]|LazyPlugin[]
|
||||||
---@param reason {[string]:string}
|
---@param reason {[string]:string}
|
||||||
---@param opts? {load_start: boolean}
|
function M.load(plugins, reason)
|
||||||
function M.load(plugins, reason, opts)
|
|
||||||
---@diagnostic disable-next-line: cast-local-type
|
---@diagnostic disable-next-line: cast-local-type
|
||||||
plugins = type(plugins) == "string" or plugins.name and { plugins } or plugins
|
plugins = type(plugins) == "string" or plugins.name and { plugins } or plugins
|
||||||
---@cast plugins (string|LazyPlugin)[]
|
---@cast plugins (string|LazyPlugin)[]
|
||||||
|
@ -47,7 +51,7 @@ function M.load(plugins, reason, opts)
|
||||||
table.insert(M.loading, plugin)
|
table.insert(M.loading, plugin)
|
||||||
|
|
||||||
Util.track({ plugin = plugin.name, start = reason.start })
|
Util.track({ plugin = plugin.name, start = reason.start })
|
||||||
M.packadd(plugin, opts and opts.load_start)
|
M.packadd(plugin)
|
||||||
|
|
||||||
if plugin.dependencies then
|
if plugin.dependencies then
|
||||||
M.load(plugin.dependencies, {})
|
M.load(plugin.dependencies, {})
|
||||||
|
@ -67,15 +71,9 @@ function M.load(plugins, reason, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
function M.packadd(plugin, load_start)
|
function M.packadd(plugin)
|
||||||
if plugin.opt then
|
|
||||||
vim.cmd.packadd(plugin.name)
|
vim.cmd.packadd(plugin.name)
|
||||||
M.source_runtime(plugin, "/after/plugin")
|
M.source_runtime(plugin, "/after/plugin")
|
||||||
elseif load_start then
|
|
||||||
vim.opt.runtimepath:append(plugin.dir)
|
|
||||||
M.source_runtime(plugin, "/plugin")
|
|
||||||
M.source_runtime(plugin, "/after/plugin")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
|
|
|
@ -70,7 +70,6 @@ end
|
||||||
|
|
||||||
function M.save_cache()
|
function M.save_cache()
|
||||||
local f = assert(uv.fs_open(cache_path, "w", 438))
|
local f = assert(uv.fs_open(cache_path, "w", 438))
|
||||||
vim.loop.fs_ftruncate(f, 0)
|
|
||||||
for modname, entry in pairs(M.cache) do
|
for modname, entry in pairs(M.cache) do
|
||||||
if entry.used then
|
if entry.used then
|
||||||
entry.modname = modname
|
entry.modname = modname
|
||||||
|
|
|
@ -34,7 +34,7 @@ local M = {}
|
||||||
---@field dir string
|
---@field dir string
|
||||||
---@field dep? boolean True if this plugin is only in the spec as a dependency
|
---@field dep? boolean True if this plugin is only in the spec as a dependency
|
||||||
---@field enabled? boolean|(fun():boolean)
|
---@field enabled? boolean|(fun():boolean)
|
||||||
---@field opt? boolean
|
---@field lazy? boolean
|
||||||
---@field dependencies? string[]
|
---@field dependencies? string[]
|
||||||
---@field _ LazyPluginState
|
---@field _ LazyPluginState
|
||||||
|
|
||||||
|
@ -145,45 +145,40 @@ function Spec:merge(old, new)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.update_state()
|
function M.update_state()
|
||||||
---@type table<"opt"|"start", table<string,FileType>>
|
---@type table<string,FileType>
|
||||||
local installed = { opt = {}, start = {} }
|
local installed = {}
|
||||||
for opt, packs in pairs(installed) do
|
Util.ls(Config.options.packpath .. "/opt", function(_, name, type)
|
||||||
Util.ls(Config.options.packpath .. "/" .. opt, function(_, name, type)
|
|
||||||
if type == "directory" or type == "link" then
|
if type == "directory" or type == "link" then
|
||||||
packs[name] = type
|
installed[name] = type
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
|
||||||
|
|
||||||
for _, plugin in pairs(Config.plugins) do
|
for _, plugin in pairs(Config.plugins) do
|
||||||
plugin._ = plugin._ or {}
|
plugin._ = plugin._ or {}
|
||||||
if plugin.opt == nil then
|
if plugin.lazy == nil then
|
||||||
local opt = plugin.dep
|
local lazy = plugin.dep
|
||||||
or Config.options.defaults.opt
|
or Config.options.defaults.lazy
|
||||||
or plugin.module
|
or plugin.module
|
||||||
or plugin.event
|
or plugin.event
|
||||||
or plugin.keys
|
or plugin.keys
|
||||||
or plugin.ft
|
or plugin.ft
|
||||||
or plugin.cmd
|
or plugin.cmd
|
||||||
plugin.opt = opt and true or false
|
plugin.lazy = lazy and true or false
|
||||||
end
|
end
|
||||||
local opt = plugin.opt and "opt" or "start"
|
plugin.dir = Config.options.packpath .. "/opt/" .. plugin.name
|
||||||
plugin.dir = Config.options.packpath .. "/" .. opt .. "/" .. plugin.name
|
|
||||||
plugin._.is_local = plugin.uri:sub(1, 4) ~= "http" and plugin.uri:sub(1, 3) ~= "git"
|
plugin._.is_local = plugin.uri:sub(1, 4) ~= "http" and plugin.uri:sub(1, 3) ~= "git"
|
||||||
plugin._.is_symlink = installed[opt][plugin.name] == "link"
|
plugin._.is_symlink = installed[plugin.name] == "link"
|
||||||
plugin._.installed = installed[opt][plugin.name] ~= nil
|
plugin._.installed = installed[plugin.name] ~= nil
|
||||||
if plugin._.is_local == plugin._.is_symlink then
|
if plugin._.is_local == plugin._.is_symlink then
|
||||||
installed[opt][plugin.name] = nil
|
installed[plugin.name] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Config.to_clean = {}
|
Config.to_clean = {}
|
||||||
for opt, packs in pairs(installed) do
|
for pack, dir_type in pairs(installed) do
|
||||||
for pack, dir_type in pairs(packs) do
|
|
||||||
table.insert(Config.to_clean, {
|
table.insert(Config.to_clean, {
|
||||||
name = pack,
|
name = pack,
|
||||||
dir = Config.options.packpath .. "/" .. opt .. "/" .. pack,
|
dir = Config.options.packpath .. "/opt/" .. pack,
|
||||||
opt = opt == "opt",
|
|
||||||
_ = {
|
_ = {
|
||||||
installed = true,
|
installed = true,
|
||||||
is_symlink = dir_type == "link",
|
is_symlink = dir_type == "link",
|
||||||
|
@ -191,7 +186,6 @@ function M.update_state()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.spec()
|
function M.spec()
|
||||||
|
@ -214,7 +208,7 @@ function M.load()
|
||||||
Util.track("spec")
|
Util.track("spec")
|
||||||
local spec = M.spec()
|
local spec = M.spec()
|
||||||
if not spec.plugins["lazy.nvim"] then
|
if not spec.plugins["lazy.nvim"] then
|
||||||
spec:add({ "folke/lazy.nvim", opt = false })
|
spec:add({ "folke/lazy.nvim", lazy = false })
|
||||||
end
|
end
|
||||||
Config.plugins = spec.plugins
|
Config.plugins = spec.plugins
|
||||||
Util.track()
|
Util.track()
|
||||||
|
|
|
@ -7,7 +7,6 @@ function M.setup(opts)
|
||||||
local Util = require("lazy.core.util")
|
local Util = require("lazy.core.util")
|
||||||
local Config = require("lazy.core.config")
|
local Config = require("lazy.core.config")
|
||||||
local Loader = require("lazy.core.loader")
|
local Loader = require("lazy.core.loader")
|
||||||
local Handler = require("lazy.core.handler")
|
|
||||||
local Plugin = require("lazy.core.plugin")
|
local Plugin = require("lazy.core.plugin")
|
||||||
|
|
||||||
Util.track("module", vim.loop.hrtime() - module_start)
|
Util.track("module", vim.loop.hrtime() - module_start)
|
||||||
|
@ -32,8 +31,8 @@ function M.setup(opts)
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
|
|
||||||
Util.track("handlers")
|
Util.track("loader")
|
||||||
Handler.setup()
|
Loader.setup()
|
||||||
Util.track()
|
Util.track()
|
||||||
|
|
||||||
local lazy_delta = vim.loop.hrtime() - module_start
|
local lazy_delta = vim.loop.hrtime() - module_start
|
||||||
|
|
|
@ -6,10 +6,10 @@ local M = {}
|
||||||
|
|
||||||
M.build = {
|
M.build = {
|
||||||
skip = function(plugin)
|
skip = function(plugin)
|
||||||
return not (plugin._.dirty and (plugin.opt == false or plugin.build))
|
return not (plugin._.dirty and plugin.build)
|
||||||
end,
|
end,
|
||||||
run = function(self)
|
run = function(self)
|
||||||
Loader.load(self.plugin, { task = "run" }, { load_start = true })
|
Loader.load(self.plugin, { task = "build" })
|
||||||
|
|
||||||
local build = self.plugin.build
|
local build = self.plugin.build
|
||||||
if build then
|
if build then
|
||||||
|
|
|
@ -30,7 +30,7 @@ end)
|
||||||
|
|
||||||
describe("plugin spec opt", function()
|
describe("plugin spec opt", function()
|
||||||
it("handles dependencies", function()
|
it("handles dependencies", function()
|
||||||
Config.options.defaults.opt = false
|
Config.options.defaults.lazy = false
|
||||||
local tests = {
|
local tests = {
|
||||||
{ "foo/bar", dependencies = { "foo/dep1", "foo/dep2" } },
|
{ "foo/bar", dependencies = { "foo/dep1", "foo/dep2" } },
|
||||||
{ "foo/bar", dependencies = { { "foo/dep1" }, "foo/dep2" } },
|
{ "foo/bar", dependencies = { { "foo/dep1" }, "foo/dep2" } },
|
||||||
|
@ -43,53 +43,53 @@ describe("plugin spec opt", function()
|
||||||
assert(vim.tbl_count(spec.plugins) == 3)
|
assert(vim.tbl_count(spec.plugins) == 3)
|
||||||
assert(#spec.plugins.bar.dependencies == 2)
|
assert(#spec.plugins.bar.dependencies == 2)
|
||||||
assert(spec.plugins.bar.dep ~= true)
|
assert(spec.plugins.bar.dep ~= true)
|
||||||
assert(spec.plugins.bar.opt == false)
|
assert(spec.plugins.bar.lazy == false)
|
||||||
assert(spec.plugins.dep1.dep == true)
|
assert(spec.plugins.dep1.dep == true)
|
||||||
assert(spec.plugins.dep1.opt == true)
|
assert(spec.plugins.dep1.lazy == true)
|
||||||
assert(spec.plugins.dep2.dep == true)
|
assert(spec.plugins.dep2.dep == true)
|
||||||
assert(spec.plugins.dep2.opt == true)
|
assert(spec.plugins.dep2.lazy == true)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles opt from dep", function()
|
it("handles opt from dep", function()
|
||||||
Config.options.defaults.opt = false
|
Config.options.defaults.lazy = false
|
||||||
local spec = Plugin.Spec.new({ "foo/dep1", { "foo/bar", dependencies = { "foo/dep1", "foo/dep2" } } })
|
local spec = Plugin.Spec.new({ "foo/dep1", { "foo/bar", dependencies = { "foo/dep1", "foo/dep2" } } })
|
||||||
Config.plugins = spec.plugins
|
Config.plugins = spec.plugins
|
||||||
Plugin.update_state()
|
Plugin.update_state()
|
||||||
assert.same(3, vim.tbl_count(spec.plugins))
|
assert.same(3, vim.tbl_count(spec.plugins))
|
||||||
assert(spec.plugins.bar.dep ~= true)
|
assert(spec.plugins.bar.dep ~= true)
|
||||||
assert(spec.plugins.bar.opt == false)
|
assert(spec.plugins.bar.lazy == false)
|
||||||
assert(spec.plugins.dep2.dep == true)
|
assert(spec.plugins.dep2.dep == true)
|
||||||
assert(spec.plugins.dep2.opt == true)
|
assert(spec.plugins.dep2.lazy == true)
|
||||||
assert(spec.plugins.dep1.dep ~= true)
|
assert(spec.plugins.dep1.dep ~= true)
|
||||||
assert(spec.plugins.dep1.opt == false)
|
assert(spec.plugins.dep1.lazy == false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles defaults opt", function()
|
it("handles defaults opt", function()
|
||||||
do
|
do
|
||||||
Config.options.defaults.opt = true
|
Config.options.defaults.lazy = true
|
||||||
local spec = Plugin.Spec.new({ "foo/bar" })
|
local spec = Plugin.Spec.new({ "foo/bar" })
|
||||||
Config.plugins = spec.plugins
|
Config.plugins = spec.plugins
|
||||||
Plugin.update_state()
|
Plugin.update_state()
|
||||||
assert(spec.plugins.bar.opt == true)
|
assert(spec.plugins.bar.lazy == true)
|
||||||
end
|
end
|
||||||
do
|
do
|
||||||
Config.options.defaults.opt = false
|
Config.options.defaults.lazy = false
|
||||||
local spec = Plugin.Spec.new({ "foo/bar" })
|
local spec = Plugin.Spec.new({ "foo/bar" })
|
||||||
Config.plugins = spec.plugins
|
Config.plugins = spec.plugins
|
||||||
Plugin.update_state()
|
Plugin.update_state()
|
||||||
assert(spec.plugins.bar.opt == false)
|
assert(spec.plugins.bar.lazy == false)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles opt from dep", function()
|
it("handles opt from dep", function()
|
||||||
Config.options.defaults.opt = false
|
Config.options.defaults.lazy = false
|
||||||
local spec = Plugin.Spec.new({ "foo/bar", module = "foo" })
|
local spec = Plugin.Spec.new({ "foo/bar", module = "foo" })
|
||||||
Config.plugins = spec.plugins
|
Config.plugins = spec.plugins
|
||||||
Plugin.update_state()
|
Plugin.update_state()
|
||||||
assert.same(1, vim.tbl_count(spec.plugins))
|
assert.same(1, vim.tbl_count(spec.plugins))
|
||||||
assert(spec.plugins.bar.dep ~= true)
|
assert(spec.plugins.bar.dep ~= true)
|
||||||
assert(spec.plugins.bar.opt == true)
|
assert(spec.plugins.bar.lazy == true)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("merges lazy loaders", function()
|
it("merges lazy loaders", function()
|
||||||
|
|
Loading…
Reference in New Issue