Skip to content

Commit 105d480

Browse files
committed
fix(runner): sync package specs after installing and before building
1 parent 656d3d1 commit 105d480

File tree

4 files changed

+58
-24
lines changed

4 files changed

+58
-24
lines changed

lua/lazy/core/plugin.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ function M.load()
342342
Config.plugins[name]._ = plugin._
343343
Config.plugins[name]._.dep = new_state.dep
344344
Config.plugins[name]._.frags = new_state.frags
345+
Config.plugins[name]._.pkg = new_state.pkg
345346
end
346347
end
347348
Util.track()

lua/lazy/manage/init.lua

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ function M.install(opts)
8383
"git.clone",
8484
{ "git.checkout", lockfile = opts.lockfile },
8585
"plugin.docs",
86-
"wait",
86+
{
87+
"wait",
88+
sync = function()
89+
require("lazy.pkg").update()
90+
Plugin.load()
91+
end,
92+
},
8793
"plugin.build",
8894
},
8995
plugins = function(plugin)
@@ -92,7 +98,6 @@ function M.install(opts)
9298
}, opts):wait(function()
9399
require("lazy.manage.lock").update()
94100
require("lazy.help").update()
95-
require("lazy.pkg").update()
96101
end)
97102
end
98103

@@ -107,7 +112,13 @@ function M.update(opts)
107112
"git.status",
108113
{ "git.checkout", lockfile = opts.lockfile },
109114
"plugin.docs",
110-
"wait",
115+
{
116+
"wait",
117+
sync = function()
118+
require("lazy.pkg").update()
119+
Plugin.load()
120+
end,
121+
},
111122
"plugin.build",
112123
{ "git.log", updated = true },
113124
},
@@ -117,7 +128,6 @@ function M.update(opts)
117128
}, opts):wait(function()
118129
require("lazy.manage.lock").update()
119130
require("lazy.help").update()
120-
require("lazy.pkg").update()
121131
end)
122132
end
123133
--

lua/lazy/manage/runner.lua

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ local Util = require("lazy.util")
88
---@field concurrency? number
99

1010
---@alias PipelineStep {task:string, opts?:TaskOptions}
11-
---@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}, plugin: LazyPlugin}
11+
---@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}, plugin: string}
1212

1313
---@class Runner
14-
---@field _plugins LazyPlugin[]
14+
---@field _plugins string[]
1515
---@field _running LazyRunnerTask[]
1616
---@field _pipeline PipelineStep[]
17+
---@field _sync PipelineStep[]
1718
---@field _on_done fun()[]
19+
---@field _syncing boolean
1820
---@field _opts RunnerOpts
1921
local Runner = {}
2022

@@ -24,13 +26,11 @@ function Runner.new(opts)
2426
self._opts = opts or {}
2527

2628
local plugins = self._opts.plugins
27-
if type(plugins) == "function" then
28-
self._plugins = vim.tbl_filter(plugins, Config.plugins)
29-
else
30-
self._plugins = plugins or Config.plugins
31-
end
29+
self._plugins = vim.tbl_map(function(plugin)
30+
return plugin.name
31+
end, type(plugins) == "function" and vim.tbl_filter(plugins, Config.plugins) or plugins or Config.plugins)
3232
table.sort(self._plugins, function(a, b)
33-
return a.name < b.name
33+
return a < b
3434
end)
3535
self._running = {}
3636
self._on_done = {}
@@ -40,6 +40,10 @@ function Runner.new(opts)
4040
return type(step) == "string" and { task = step } or { task = step[1], opts = step }
4141
end, self._opts.pipeline)
4242

43+
self._sync = vim.tbl_filter(function(step)
44+
return step.task == "wait"
45+
end, self._pipeline)
46+
4347
return self
4448
end
4549

@@ -57,14 +61,31 @@ function Runner:_resume(entry)
5761
end
5862

5963
function Runner:resume(waiting)
64+
if self._syncing then
65+
return true
66+
end
6067
if waiting then
61-
for _, entry in ipairs(self._running) do
62-
if entry.status then
63-
if entry.status.waiting then
64-
entry.status.waiting = false
65-
entry.plugin._.working = true
68+
local sync = self._sync[1]
69+
table.remove(self._sync, 1)
70+
if sync then
71+
self._syncing = true
72+
vim.schedule(function()
73+
if sync.opts and type(sync.opts.sync) == "function" then
74+
sync.opts.sync(self)
6675
end
67-
end
76+
for _, entry in ipairs(self._running) do
77+
if entry.status then
78+
if entry.status.waiting then
79+
entry.status.waiting = false
80+
local plugin = Config.plugins[entry.plugin]
81+
if plugin then
82+
plugin._.working = true
83+
end
84+
end
85+
end
86+
end
87+
self._syncing = false
88+
end)
6889
end
6990
end
7091
local running = 0
@@ -78,7 +99,7 @@ function Runner:resume(waiting)
7899
end
79100
end
80101
end
81-
return running > 0 or (not waiting and self:resume(true))
102+
return self._syncing or running > 0 or (not waiting and self:resume(true))
82103
end
83104

84105
function Runner:start()
@@ -88,7 +109,7 @@ function Runner:start()
88109
if ok then
89110
table.insert(self._running, { co = co, status = {}, plugin = plugin })
90111
else
91-
Util.error("Could not start tasks for " .. plugin.name .. "\n" .. err)
112+
Util.error("Could not start tasks for " .. plugin .. "\n" .. err)
92113
end
93114
end
94115

@@ -107,8 +128,9 @@ function Runner:start()
107128
end
108129

109130
---@async
110-
---@param plugin LazyPlugin
111-
function Runner:run_pipeline(plugin)
131+
---@param name string
132+
function Runner:run_pipeline(name)
133+
local plugin = Config.plugins[name]
112134
plugin._.working = true
113135
coroutine.yield()
114136
for _, step in ipairs(self._pipeline) do
@@ -117,6 +139,7 @@ function Runner:run_pipeline(plugin)
117139
coroutine.yield({ waiting = true })
118140
plugin._.working = true
119141
else
142+
plugin = Config.plugins[name] or plugin
120143
local task = self:queue(plugin, step.task, step.opts)
121144
if task then
122145
coroutine.yield({ task = task })

lua/lazy/pkg/rockspec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ function M.deps(plugin)
1212
local root = Config.options.rocks.root .. "/" .. plugin.name
1313
local manifest_file = root .. "/lib/luarocks/rocks-5.1/manifest"
1414
local manifest = {}
15-
local ok = pcall(function()
15+
pcall(function()
1616
local load, err = loadfile(manifest_file, "t", manifest)
1717
if not load then
1818
error(err)
1919
end
2020
load()
2121
end)
22-
return manifest and vim.tbl_keys(manifest.repository or {})
22+
return vim.tbl_keys(manifest.repository or {})
2323
end
2424

2525
---@class RockSpec

0 commit comments

Comments
 (0)