fix(install): dont try re-installing failed missing plugins during startup. Fixes #303

This commit is contained in:
Folke Lemaitre 2023-01-03 22:50:14 +01:00
parent 1fd80159d0
commit c85f929bd9
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 34 additions and 9 deletions

View File

@ -33,7 +33,12 @@ function M.setup()
-- install missing plugins -- install missing plugins
if Config.options.install.missing then if Config.options.install.missing then
Util.track("install") Util.track("install")
local count = 0
while M.install_missing() do while M.install_missing() do
count = count + 1
if count > 5 then
break
end
end end
Util.track() Util.track()
end end
@ -51,7 +56,7 @@ end
-- multiple rounds can happen when importing a spec from a missing plugin -- multiple rounds can happen when importing a spec from a missing plugin
function M.install_missing() function M.install_missing()
for _, plugin in pairs(Config.plugins) do for _, plugin in pairs(Config.plugins) do
if not plugin._.installed then if not (plugin._.installed or Plugin.has_errors(plugin)) then
for _, colorscheme in ipairs(Config.options.install.colorscheme) do for _, colorscheme in ipairs(Config.options.install.colorscheme) do
if pcall(vim.cmd.colorscheme, colorscheme) then if pcall(vim.cmd.colorscheme, colorscheme) then
break break
@ -64,8 +69,6 @@ function M.install_missing()
Cache.indexed[p.dir] = nil Cache.indexed[p.dir] = nil
end end
end end
-- clear plugins. no need to merge in this stage
Config.plugins = {}
-- reload plugins -- reload plugins
Plugin.load() Plugin.load()
return true return true

View File

@ -326,4 +326,14 @@ function M.find(path)
end end
end end
---@param plugin LazyPlugin
function M.has_errors(plugin)
for _, task in ipairs(plugin._.tasks or {}) do
if task.error then
return true
end
end
return false
end
return M return M

View File

@ -1,6 +1,7 @@
local Config = require("lazy.core.config") local Config = require("lazy.core.config")
local Manage = require("lazy.manage") local Manage = require("lazy.manage")
local Util = require("lazy.util") local Util = require("lazy.util")
local Plugin = require("lazy.core.plugin")
local Git = require("lazy.manage.git") local Git = require("lazy.manage.git")
local M = {} local M = {}
@ -31,6 +32,16 @@ function M.fast_check(opts)
end end
function M.check() function M.check()
local errors = false
for _, plugin in pairs(Config.plugins) do
if Plugin.has_errors(plugin) then
errors = true
break
end
end
if errors then
vim.defer_fn(M.check, Config.options.checker.frequency * 1000)
else
Manage.check({ Manage.check({
show = false, show = false,
concurrency = Config.options.checker.concurrency, concurrency = Config.options.checker.concurrency,
@ -38,6 +49,7 @@ function M.check()
M.report() M.report()
vim.defer_fn(M.check, Config.options.checker.frequency * 1000) vim.defer_fn(M.check, Config.options.checker.frequency * 1000)
end) end)
end
end end
---@param notify? boolean ---@param notify? boolean