From d5686efbd00942b3e38de7c08b8df69d961b02f0 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 23 Jul 2024 13:31:20 +0200 Subject: [PATCH] feat: added `opts.git.cooldown` to allow updating plugins on slow connections. Fixes #1656 --- lua/lazy/core/config.lua | 4 ++++ lua/lazy/manage/task/git.lua | 16 +++++++++++++++- lua/lazy/types.lua | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index e02ed0b..f5633b1 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -41,6 +41,10 @@ M.defaults = { rate = 2, duration = 5 * 1000, -- in ms }, + -- Time in seconds to wait before running fetch again for a plugin. + -- Repeated update/check operations will not run again until this + -- cooldown period has passed. + cooldown = 0, }, pkg = { enabled = true, diff --git a/lua/lazy/manage/task/git.lua b/lua/lazy/manage/task/git.lua index bd7ee38..c54c809 100644 --- a/lua/lazy/manage/task/git.lua +++ b/lua/lazy/manage/task/git.lua @@ -40,6 +40,15 @@ function throttle.wait() end end +---@param plugin LazyPlugin +local function cooldown(plugin) + if not plugin._.last_check then + return false + end + local delta = (vim.uv.now() - plugin._.last_check) / 1000 + return delta < Config.options.git.cooldown +end + ---@type table local M = {} @@ -266,7 +275,7 @@ M.status = { -- fetches all needed origin branches M.fetch = { skip = function(plugin) - return not plugin._.installed or plugin._.is_local + return not plugin._.installed or plugin._.is_local or cooldown(plugin) end, ---@async @@ -287,6 +296,11 @@ M.fetch = { self:spawn("git", { args = args, cwd = self.plugin.dir, + on_exit = function(ok) + if ok then + self.plugin._.last_check = vim.uv.now() + end + end, }) end, } diff --git a/lua/lazy/types.lua b/lua/lazy/types.lua index 0a10467..5921169 100644 --- a/lua/lazy/types.lua +++ b/lua/lazy/types.lua @@ -20,6 +20,7 @@ ---@field tasks? LazyTask[] ---@field updated? {from:string, to:string} ---@field updates? {from:GitInfo, to:GitInfo} +---@field last_check? number ---@field working? boolean ---@field pkg? LazyPkg