mirror of https://github.com/folke/lazy.nvim.git
fix(runner): sync package specs after installing and before building
This commit is contained in:
parent
656d3d1f5b
commit
105d4805ad
|
@ -342,6 +342,7 @@ function M.load()
|
||||||
Config.plugins[name]._ = plugin._
|
Config.plugins[name]._ = plugin._
|
||||||
Config.plugins[name]._.dep = new_state.dep
|
Config.plugins[name]._.dep = new_state.dep
|
||||||
Config.plugins[name]._.frags = new_state.frags
|
Config.plugins[name]._.frags = new_state.frags
|
||||||
|
Config.plugins[name]._.pkg = new_state.pkg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Util.track()
|
Util.track()
|
||||||
|
|
|
@ -83,7 +83,13 @@ function M.install(opts)
|
||||||
"git.clone",
|
"git.clone",
|
||||||
{ "git.checkout", lockfile = opts.lockfile },
|
{ "git.checkout", lockfile = opts.lockfile },
|
||||||
"plugin.docs",
|
"plugin.docs",
|
||||||
|
{
|
||||||
"wait",
|
"wait",
|
||||||
|
sync = function()
|
||||||
|
require("lazy.pkg").update()
|
||||||
|
Plugin.load()
|
||||||
|
end,
|
||||||
|
},
|
||||||
"plugin.build",
|
"plugin.build",
|
||||||
},
|
},
|
||||||
plugins = function(plugin)
|
plugins = function(plugin)
|
||||||
|
@ -92,7 +98,6 @@ function M.install(opts)
|
||||||
}, opts):wait(function()
|
}, opts):wait(function()
|
||||||
require("lazy.manage.lock").update()
|
require("lazy.manage.lock").update()
|
||||||
require("lazy.help").update()
|
require("lazy.help").update()
|
||||||
require("lazy.pkg").update()
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -107,7 +112,13 @@ function M.update(opts)
|
||||||
"git.status",
|
"git.status",
|
||||||
{ "git.checkout", lockfile = opts.lockfile },
|
{ "git.checkout", lockfile = opts.lockfile },
|
||||||
"plugin.docs",
|
"plugin.docs",
|
||||||
|
{
|
||||||
"wait",
|
"wait",
|
||||||
|
sync = function()
|
||||||
|
require("lazy.pkg").update()
|
||||||
|
Plugin.load()
|
||||||
|
end,
|
||||||
|
},
|
||||||
"plugin.build",
|
"plugin.build",
|
||||||
{ "git.log", updated = true },
|
{ "git.log", updated = true },
|
||||||
},
|
},
|
||||||
|
@ -117,7 +128,6 @@ function M.update(opts)
|
||||||
}, opts):wait(function()
|
}, opts):wait(function()
|
||||||
require("lazy.manage.lock").update()
|
require("lazy.manage.lock").update()
|
||||||
require("lazy.help").update()
|
require("lazy.help").update()
|
||||||
require("lazy.pkg").update()
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
|
|
|
@ -8,13 +8,15 @@ 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}, plugin: LazyPlugin}
|
---@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}, plugin: string}
|
||||||
|
|
||||||
---@class Runner
|
---@class Runner
|
||||||
---@field _plugins LazyPlugin[]
|
---@field _plugins string[]
|
||||||
---@field _running LazyRunnerTask[]
|
---@field _running LazyRunnerTask[]
|
||||||
---@field _pipeline PipelineStep[]
|
---@field _pipeline PipelineStep[]
|
||||||
|
---@field _sync PipelineStep[]
|
||||||
---@field _on_done fun()[]
|
---@field _on_done fun()[]
|
||||||
|
---@field _syncing boolean
|
||||||
---@field _opts RunnerOpts
|
---@field _opts RunnerOpts
|
||||||
local Runner = {}
|
local Runner = {}
|
||||||
|
|
||||||
|
@ -24,13 +26,11 @@ function Runner.new(opts)
|
||||||
self._opts = opts or {}
|
self._opts = opts or {}
|
||||||
|
|
||||||
local plugins = self._opts.plugins
|
local plugins = self._opts.plugins
|
||||||
if type(plugins) == "function" then
|
self._plugins = vim.tbl_map(function(plugin)
|
||||||
self._plugins = vim.tbl_filter(plugins, Config.plugins)
|
return plugin.name
|
||||||
else
|
end, type(plugins) == "function" and vim.tbl_filter(plugins, Config.plugins) or plugins or Config.plugins)
|
||||||
self._plugins = plugins or Config.plugins
|
|
||||||
end
|
|
||||||
table.sort(self._plugins, function(a, b)
|
table.sort(self._plugins, function(a, b)
|
||||||
return a.name < b.name
|
return a < b
|
||||||
end)
|
end)
|
||||||
self._running = {}
|
self._running = {}
|
||||||
self._on_done = {}
|
self._on_done = {}
|
||||||
|
@ -40,6 +40,10 @@ function Runner.new(opts)
|
||||||
return type(step) == "string" and { task = step } or { task = step[1], opts = step }
|
return type(step) == "string" and { task = step } or { task = step[1], opts = step }
|
||||||
end, self._opts.pipeline)
|
end, self._opts.pipeline)
|
||||||
|
|
||||||
|
self._sync = vim.tbl_filter(function(step)
|
||||||
|
return step.task == "wait"
|
||||||
|
end, self._pipeline)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,16 +61,33 @@ function Runner:_resume(entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Runner:resume(waiting)
|
function Runner:resume(waiting)
|
||||||
|
if self._syncing then
|
||||||
|
return true
|
||||||
|
end
|
||||||
if waiting then
|
if waiting then
|
||||||
|
local sync = self._sync[1]
|
||||||
|
table.remove(self._sync, 1)
|
||||||
|
if sync then
|
||||||
|
self._syncing = true
|
||||||
|
vim.schedule(function()
|
||||||
|
if sync.opts and type(sync.opts.sync) == "function" then
|
||||||
|
sync.opts.sync(self)
|
||||||
|
end
|
||||||
for _, entry in ipairs(self._running) do
|
for _, entry in ipairs(self._running) do
|
||||||
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
|
||||||
entry.plugin._.working = true
|
local plugin = Config.plugins[entry.plugin]
|
||||||
|
if plugin then
|
||||||
|
plugin._.working = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self._syncing = false
|
||||||
|
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
|
||||||
|
@ -78,7 +99,7 @@ function Runner:resume(waiting)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return running > 0 or (not waiting and self:resume(true))
|
return self._syncing or running > 0 or (not waiting and self:resume(true))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Runner:start()
|
function Runner:start()
|
||||||
|
@ -88,7 +109,7 @@ function Runner:start()
|
||||||
if ok then
|
if ok then
|
||||||
table.insert(self._running, { co = co, status = {}, plugin = plugin })
|
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 .. "\n" .. err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -107,8 +128,9 @@ function Runner:start()
|
||||||
end
|
end
|
||||||
|
|
||||||
---@async
|
---@async
|
||||||
---@param plugin LazyPlugin
|
---@param name string
|
||||||
function Runner:run_pipeline(plugin)
|
function Runner:run_pipeline(name)
|
||||||
|
local plugin = Config.plugins[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
|
||||||
|
@ -117,6 +139,7 @@ function Runner:run_pipeline(plugin)
|
||||||
coroutine.yield({ waiting = true })
|
coroutine.yield({ waiting = true })
|
||||||
plugin._.working = true
|
plugin._.working = true
|
||||||
else
|
else
|
||||||
|
plugin = Config.plugins[name] or plugin
|
||||||
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 })
|
||||||
|
|
|
@ -12,14 +12,14 @@ function M.deps(plugin)
|
||||||
local root = Config.options.rocks.root .. "/" .. plugin.name
|
local root = Config.options.rocks.root .. "/" .. plugin.name
|
||||||
local manifest_file = root .. "/lib/luarocks/rocks-5.1/manifest"
|
local manifest_file = root .. "/lib/luarocks/rocks-5.1/manifest"
|
||||||
local manifest = {}
|
local manifest = {}
|
||||||
local ok = pcall(function()
|
pcall(function()
|
||||||
local load, err = loadfile(manifest_file, "t", manifest)
|
local load, err = loadfile(manifest_file, "t", manifest)
|
||||||
if not load then
|
if not load then
|
||||||
error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
load()
|
load()
|
||||||
end)
|
end)
|
||||||
return manifest and vim.tbl_keys(manifest.repository or {})
|
return vim.tbl_keys(manifest.repository or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class RockSpec
|
---@class RockSpec
|
||||||
|
|
Loading…
Reference in New Issue