mirror of https://github.com/folke/lazy.nvim.git
test: fixes
This commit is contained in:
parent
bd397ff1e3
commit
77edda11bf
|
@ -11,7 +11,7 @@ local Util = require("lazy.util")
|
||||||
---@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}, plugin: string}
|
---@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}, plugin: string}
|
||||||
|
|
||||||
---@class Runner
|
---@class Runner
|
||||||
---@field _plugins string[]
|
---@field _plugins table<string,LazyPlugin>
|
||||||
---@field _running LazyRunnerTask[]
|
---@field _running LazyRunnerTask[]
|
||||||
---@field _pipeline PipelineStep[]
|
---@field _pipeline PipelineStep[]
|
||||||
---@field _sync PipelineStep[]
|
---@field _sync PipelineStep[]
|
||||||
|
@ -26,12 +26,17 @@ function Runner.new(opts)
|
||||||
self._opts = opts or {}
|
self._opts = opts or {}
|
||||||
|
|
||||||
local plugins = self._opts.plugins
|
local plugins = self._opts.plugins
|
||||||
self._plugins = vim.tbl_map(function(plugin)
|
---@type LazyPlugin[]
|
||||||
return plugin.name
|
local pp = {}
|
||||||
end, type(plugins) == "function" and vim.tbl_filter(plugins, Config.plugins) or plugins or Config.plugins)
|
if type(plugins) == "function" then
|
||||||
table.sort(self._plugins, function(a, b)
|
pp = vim.tbl_filter(plugins, Config.plugins)
|
||||||
return a < b
|
else
|
||||||
end)
|
pp = plugins or Config.plugins
|
||||||
|
end
|
||||||
|
self._plugins = {}
|
||||||
|
for _, plugin in ipairs(pp) do
|
||||||
|
self._plugins[plugin.name] = plugin
|
||||||
|
end
|
||||||
self._running = {}
|
self._running = {}
|
||||||
self._on_done = {}
|
self._on_done = {}
|
||||||
|
|
||||||
|
@ -47,6 +52,10 @@ function Runner.new(opts)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Runner:plugin(name)
|
||||||
|
return Config.plugins[name] or self._plugins[name]
|
||||||
|
end
|
||||||
|
|
||||||
---@param entry LazyRunnerTask
|
---@param entry LazyRunnerTask
|
||||||
function Runner:_resume(entry)
|
function Runner:_resume(entry)
|
||||||
if entry.status.task and not entry.status.task:is_done() then
|
if entry.status.task and not entry.status.task:is_done() then
|
||||||
|
@ -77,7 +86,7 @@ function Runner:resume(waiting)
|
||||||
if entry.status then
|
if entry.status then
|
||||||
if entry.status.waiting then
|
if entry.status.waiting then
|
||||||
entry.status.waiting = false
|
entry.status.waiting = false
|
||||||
local plugin = Config.plugins[entry.plugin]
|
local plugin = self:plugin(entry.plugin)
|
||||||
if plugin then
|
if plugin then
|
||||||
plugin._.working = true
|
plugin._.working = true
|
||||||
end
|
end
|
||||||
|
@ -103,13 +112,16 @@ function Runner:resume(waiting)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Runner:start()
|
function Runner:start()
|
||||||
for _, plugin in pairs(self._plugins) do
|
---@type string[]
|
||||||
|
local names = vim.tbl_keys(self._plugins)
|
||||||
|
table.sort(names)
|
||||||
|
for _, name in pairs(names) do
|
||||||
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, name)
|
||||||
if ok then
|
if ok then
|
||||||
table.insert(self._running, { co = co, status = {}, plugin = plugin })
|
table.insert(self._running, { co = co, status = {}, plugin = name })
|
||||||
else
|
else
|
||||||
Util.error("Could not start tasks for " .. plugin .. "\n" .. err)
|
Util.error("Could not start tasks for " .. name .. "\n" .. err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -130,7 +142,7 @@ end
|
||||||
---@async
|
---@async
|
||||||
---@param name string
|
---@param name string
|
||||||
function Runner:run_pipeline(name)
|
function Runner:run_pipeline(name)
|
||||||
local plugin = Config.plugins[name]
|
local plugin = self:plugin(name)
|
||||||
plugin._.working = true
|
plugin._.working = true
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
for _, step in ipairs(self._pipeline) do
|
for _, step in ipairs(self._pipeline) do
|
||||||
|
@ -139,7 +151,7 @@ function Runner:run_pipeline(name)
|
||||||
coroutine.yield({ waiting = true })
|
coroutine.yield({ waiting = true })
|
||||||
plugin._.working = true
|
plugin._.working = true
|
||||||
else
|
else
|
||||||
plugin = Config.plugins[name] or plugin
|
plugin = self:plugin(name)
|
||||||
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 })
|
||||||
|
|
|
@ -102,7 +102,7 @@ describe("task", function()
|
||||||
task:start()
|
task:start()
|
||||||
assert(task:is_running())
|
assert(task:is_running())
|
||||||
task:wait()
|
task:wait()
|
||||||
assert(task.output == "foo\nbar\n" or task.output == "bar\nfoo\n")
|
assert(task.output == "foo\nbar\n" or task.output == "bar\nfoo\n", task.output)
|
||||||
assert(done)
|
assert(done)
|
||||||
assert(not task.error)
|
assert(not task.error)
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue