From 7613ab2abb1bd99e039ae02030bc2c48b7626925 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 17 Oct 2023 10:29:48 +0200 Subject: [PATCH] fix(ui): running tasks are now less twitchy --- lua/lazy/manage/runner.lua | 25 ++++++++++++++++++++----- lua/lazy/types.lua | 1 + lua/lazy/view/sections.lua | 3 +++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lua/lazy/manage/runner.lua b/lua/lazy/manage/runner.lua index 85c20be..0ac0c15 100644 --- a/lua/lazy/manage/runner.lua +++ b/lua/lazy/manage/runner.lua @@ -8,7 +8,7 @@ local Util = require("lazy.util") ---@field concurrency? number ---@alias PipelineStep {task:string, opts?:TaskOptions} ----@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}} +---@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}, plugin: LazyPlugin} ---@class Runner ---@field _plugins LazyPlugin[] @@ -29,6 +29,9 @@ function Runner.new(opts) else self._plugins = plugins or Config.plugins end + table.sort(self._plugins, function(a, b) + return a.name < b.name + end) self._running = {} self._on_done = {} @@ -54,12 +57,19 @@ function Runner:_resume(entry) end function Runner:resume(waiting) + if waiting then + for _, entry in ipairs(self._running) do + if entry.status then + if entry.status.waiting then + entry.status.waiting = false + entry.plugin._.working = true + end + end + end + end local running = 0 for _, entry in ipairs(self._running) do if entry.status then - if waiting and entry.status.waiting then - entry.status.waiting = false - end if not entry.status.waiting and self:_resume(entry) then running = running + 1 if self._opts.concurrency and running >= self._opts.concurrency then @@ -76,7 +86,7 @@ function Runner:start() local co = coroutine.create(self.run_pipeline) local ok, err = coroutine.resume(co, self, plugin) if ok then - table.insert(self._running, { co = co, status = {} }) + table.insert(self._running, { co = co, status = {}, plugin = plugin }) else Util.error("Could not start tasks for " .. plugin.name .. "\n" .. err) end @@ -99,21 +109,26 @@ end ---@async ---@param plugin LazyPlugin function Runner:run_pipeline(plugin) + plugin._.working = true coroutine.yield() for _, step in ipairs(self._pipeline) do if step.task == "wait" then + plugin._.working = false coroutine.yield({ waiting = true }) + plugin._.working = true else local task = self:queue(plugin, step.task, step.opts) if task then coroutine.yield({ task = task }) assert(task:is_done()) if task.error then + plugin._.working = false return end end end end + plugin._.working = false end ---@param plugin LazyPlugin diff --git a/lua/lazy/types.lua b/lua/lazy/types.lua index a3dd9b9..222acbe 100644 --- a/lua/lazy/types.lua +++ b/lua/lazy/types.lua @@ -8,6 +8,7 @@ ---@field loaded? {[string]:string}|{time:number} ---@field installed? boolean ---@field tasks? LazyTask[] +---@field working? boolean ---@field dirty? boolean ---@field updated? {from:string, to:string} ---@field is_local? boolean diff --git a/lua/lazy/view/sections.lua b/lua/lazy/view/sections.lua index 8325332..0c1f578 100644 --- a/lua/lazy/view/sections.lua +++ b/lua/lazy/view/sections.lua @@ -24,6 +24,9 @@ return { }, { filter = function(plugin) + if plugin._.working then + return true + end return has_task(plugin, function(task) return task:is_running() end)