mirror of https://github.com/folke/lazy.nvim.git
fix(ui): running tasks are now less twitchy
This commit is contained in:
parent
c7298a10db
commit
7613ab2abb
|
@ -8,7 +8,7 @@ local Util = require("lazy.util")
|
||||||
---@field concurrency? number
|
---@field concurrency? number
|
||||||
|
|
||||||
---@alias PipelineStep {task:string, opts?:TaskOptions}
|
---@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
|
---@class Runner
|
||||||
---@field _plugins LazyPlugin[]
|
---@field _plugins LazyPlugin[]
|
||||||
|
@ -29,6 +29,9 @@ function Runner.new(opts)
|
||||||
else
|
else
|
||||||
self._plugins = plugins or Config.plugins
|
self._plugins = plugins or Config.plugins
|
||||||
end
|
end
|
||||||
|
table.sort(self._plugins, function(a, b)
|
||||||
|
return a.name < b.name
|
||||||
|
end)
|
||||||
self._running = {}
|
self._running = {}
|
||||||
self._on_done = {}
|
self._on_done = {}
|
||||||
|
|
||||||
|
@ -54,12 +57,19 @@ function Runner:_resume(entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Runner:resume(waiting)
|
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
|
local running = 0
|
||||||
for _, entry in ipairs(self._running) do
|
for _, entry in ipairs(self._running) do
|
||||||
if entry.status then
|
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
|
if not entry.status.waiting and self:_resume(entry) then
|
||||||
running = running + 1
|
running = running + 1
|
||||||
if self._opts.concurrency and running >= self._opts.concurrency then
|
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 co = coroutine.create(self.run_pipeline)
|
||||||
local ok, err = coroutine.resume(co, self, plugin)
|
local ok, err = coroutine.resume(co, self, plugin)
|
||||||
if ok then
|
if ok then
|
||||||
table.insert(self._running, { co = co, status = {} })
|
table.insert(self._running, { co = co, status = {}, plugin = plugin })
|
||||||
else
|
else
|
||||||
Util.error("Could not start tasks for " .. plugin.name .. "\n" .. err)
|
Util.error("Could not start tasks for " .. plugin.name .. "\n" .. err)
|
||||||
end
|
end
|
||||||
|
@ -99,21 +109,26 @@ end
|
||||||
---@async
|
---@async
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
function Runner:run_pipeline(plugin)
|
function Runner:run_pipeline(plugin)
|
||||||
|
plugin._.working = true
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
for _, step in ipairs(self._pipeline) do
|
for _, step in ipairs(self._pipeline) do
|
||||||
if step.task == "wait" then
|
if step.task == "wait" then
|
||||||
|
plugin._.working = false
|
||||||
coroutine.yield({ waiting = true })
|
coroutine.yield({ waiting = true })
|
||||||
|
plugin._.working = true
|
||||||
else
|
else
|
||||||
local task = self:queue(plugin, step.task, step.opts)
|
local task = self:queue(plugin, step.task, step.opts)
|
||||||
if task then
|
if task then
|
||||||
coroutine.yield({ task = task })
|
coroutine.yield({ task = task })
|
||||||
assert(task:is_done())
|
assert(task:is_done())
|
||||||
if task.error then
|
if task.error then
|
||||||
|
plugin._.working = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
plugin._.working = false
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
---@field loaded? {[string]:string}|{time:number}
|
---@field loaded? {[string]:string}|{time:number}
|
||||||
---@field installed? boolean
|
---@field installed? boolean
|
||||||
---@field tasks? LazyTask[]
|
---@field tasks? LazyTask[]
|
||||||
|
---@field working? boolean
|
||||||
---@field dirty? boolean
|
---@field dirty? boolean
|
||||||
---@field updated? {from:string, to:string}
|
---@field updated? {from:string, to:string}
|
||||||
---@field is_local? boolean
|
---@field is_local? boolean
|
||||||
|
|
|
@ -24,6 +24,9 @@ return {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter = function(plugin)
|
filter = function(plugin)
|
||||||
|
if plugin._.working then
|
||||||
|
return true
|
||||||
|
end
|
||||||
return has_task(plugin, function(task)
|
return has_task(plugin, function(task)
|
||||||
return task:is_running()
|
return task:is_running()
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue