From c85f929bd98032b35e09fbc5a510884caaa8a5c3 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 3 Jan 2023 22:50:14 +0100 Subject: [PATCH] fix(install): dont try re-installing failed missing plugins during startup. Fixes #303 --- lua/lazy/core/loader.lua | 9 ++++++--- lua/lazy/core/plugin.lua | 10 ++++++++++ lua/lazy/manage/checker.lua | 24 ++++++++++++++++++------ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index f9f2620..2cfdfe8 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -33,7 +33,12 @@ function M.setup() -- install missing plugins if Config.options.install.missing then Util.track("install") + local count = 0 while M.install_missing() do + count = count + 1 + if count > 5 then + break + end end Util.track() end @@ -51,7 +56,7 @@ end -- 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 + if not (plugin._.installed or Plugin.has_errors(plugin)) then for _, colorscheme in ipairs(Config.options.install.colorscheme) do if pcall(vim.cmd.colorscheme, colorscheme) then break @@ -64,8 +69,6 @@ function M.install_missing() Cache.indexed[p.dir] = nil end end - -- clear plugins. no need to merge in this stage - Config.plugins = {} -- reload plugins Plugin.load() return true diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index 2b3fbf2..3825960 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -326,4 +326,14 @@ function M.find(path) 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 diff --git a/lua/lazy/manage/checker.lua b/lua/lazy/manage/checker.lua index 79c265d..5597bbc 100644 --- a/lua/lazy/manage/checker.lua +++ b/lua/lazy/manage/checker.lua @@ -1,6 +1,7 @@ local Config = require("lazy.core.config") local Manage = require("lazy.manage") local Util = require("lazy.util") +local Plugin = require("lazy.core.plugin") local Git = require("lazy.manage.git") local M = {} @@ -31,13 +32,24 @@ function M.fast_check(opts) end function M.check() - Manage.check({ - show = false, - concurrency = Config.options.checker.concurrency, - }):wait(function() - M.report() + 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) - end) + else + Manage.check({ + show = false, + concurrency = Config.options.checker.concurrency, + }):wait(function() + M.report() + vim.defer_fn(M.check, Config.options.checker.frequency * 1000) + end) + end end ---@param notify? boolean