mirror of https://github.com/folke/lazy.nvim.git
feat(loader): incrementally install missing plugins and rebuild spec, so imported specs from plugins work as expected
This commit is contained in:
parent
919b7f5de3
commit
2d06faa941
|
@ -2,6 +2,7 @@ local Util = require("lazy.core.util")
|
|||
local Config = require("lazy.core.config")
|
||||
local Handler = require("lazy.core.handler")
|
||||
local Cache = require("lazy.core.cache")
|
||||
local Plugin = require("lazy.core.plugin")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
@ -26,9 +27,29 @@ function M.setup()
|
|||
end,
|
||||
})
|
||||
|
||||
-- load the plugins
|
||||
Plugin.load()
|
||||
|
||||
-- install missing plugins
|
||||
if Config.options.install.missing then
|
||||
Util.track("install")
|
||||
while M.install_missing() do
|
||||
end
|
||||
Util.track()
|
||||
end
|
||||
|
||||
-- report any warnings & errors
|
||||
Config.spec:report()
|
||||
|
||||
-- setup handlers
|
||||
Util.track("handlers")
|
||||
Handler.setup()
|
||||
Util.track()
|
||||
end
|
||||
|
||||
-- this will incrementally install missing plugins
|
||||
-- multiple rounds can happen when importing a spec from a missing plugin
|
||||
function M.install_missing()
|
||||
for _, plugin in pairs(Config.plugins) do
|
||||
if not plugin._.installed then
|
||||
for _, colorscheme in ipairs(Config.options.install.colorscheme) do
|
||||
|
@ -37,16 +58,19 @@ function M.setup()
|
|||
end
|
||||
end
|
||||
require("lazy.manage").install({ wait = true, lockfile = true })
|
||||
break
|
||||
-- remove and installed plugins from indexed, so cache will index again
|
||||
for _, p in pairs(Config.plugins) do
|
||||
if p._.installed then
|
||||
Cache.indexed[p.dir] = nil
|
||||
end
|
||||
end
|
||||
Util.track()
|
||||
-- clear plugins. no need to merge in this stage
|
||||
Config.plugins = {}
|
||||
-- reload plugins
|
||||
Plugin.load()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- setup handlers
|
||||
Util.track("handlers")
|
||||
Handler.setup()
|
||||
Util.track()
|
||||
end
|
||||
|
||||
-- Startup sequence
|
||||
|
|
|
@ -80,18 +80,23 @@ function Spec:add(plugin, is_dep)
|
|||
end
|
||||
|
||||
function Spec:error(msg)
|
||||
self:notify(msg, vim.log.levels.ERROR)
|
||||
self:log(msg, vim.log.levels.ERROR)
|
||||
end
|
||||
|
||||
function Spec:warn(msg)
|
||||
self:notify(msg, vim.log.levels.WARN)
|
||||
self:log(msg, vim.log.levels.WARN)
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
---@param level number
|
||||
function Spec:notify(msg, level)
|
||||
function Spec:log(msg, level)
|
||||
self.notifs[#self.notifs + 1] = { msg = msg, level = level, file = self.importing }
|
||||
Util.notify(msg, level)
|
||||
end
|
||||
|
||||
function Spec:report()
|
||||
for _, notif in ipairs(self.notifs) do
|
||||
Util.notify(notif.msg, notif.level)
|
||||
end
|
||||
end
|
||||
|
||||
---@param spec LazySpec|LazySpecImport
|
||||
|
|
|
@ -49,9 +49,6 @@ function M.setup(spec, opts)
|
|||
Config.setup(opts)
|
||||
Util.track()
|
||||
|
||||
-- load the plugins
|
||||
Plugin.load()
|
||||
|
||||
-- setup loader and handlers
|
||||
Loader.setup()
|
||||
|
||||
|
|
Loading…
Reference in New Issue