@@ -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
1921local 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
4448end
4549
@@ -57,14 +61,31 @@ function Runner:_resume(entry)
5761end
5862
5963function 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 ))
82103end
83104
84105function 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()
107128end
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 })
0 commit comments