---@class LazyHandler---@field type LazyHandlerTypes---@field extends? LazyHandler---@field active table<string,table<string,string>>---@field managed table<string,string> mapping handler keys to plugin names---@field super LazyHandlerlocalM={}---@enum LazyHandlerTypesM.types={keys="keys",event="event",cmd="cmd",ft="ft",}---@type table<string,LazyHandler>M.handlers={}
---@param type LazyHandlerTypesfunctionM.new(type)---@type LazyHandlerlocalhandler=require("lazy.core.handler."..type)localsuper=handler.extendsorMlocalself=setmetatable({},{__index=setmetatable(handler,{__index=super})})self.super=superself.active={}self.managed={}self.type=typereturnselfend
localfunctionrm(dir)localstat=vim.uv.fs_lstat(dir)assert(statandstat.type=="directory",dir.." should be a directory!")Util.walk(dir,function(path,_,type)iftype=="directory"thenvim.uv.fs_rmdir(path)elsevim.uv.fs_unlink(path)endend)vim.uv.fs_rmdir(dir)end
---@param plugin LazyPlugin---@param step PipelineStep---@return LazyTask?functionRunner:queue(plugin,step)assert(self._runningandself._running:running(),"Runner is not running")localdef=vim.split(step.task,".",{plain=true})---@type LazyTaskDeflocaltask_def=require("lazy.manage.task."..def[1])[def[2]]assert(task_def,"Task not found: "..step.task)localopts=step.optsor{}ifnot(task_def.skipandtask_def.skip(plugin,opts))thenreturnTask.new(plugin,def[2],task_def.run,opts)endend
---@async---@param resume? booleanlocalfunctioncontinue(resume)active=0waiting=0wait_step=nillocalnext={}---@type string[]-- check running tasksfor_,nameinipairs(names)dostate[name]=state[name]or{step=0}locals=state[name]localis_running=s.taskands.task:running()localstep=self._pipeline[s.step]--- 如果任务正在运行,增加 active 计数ifis_runningthen-- still runningactive=active+1-- selene:allow(empty_if)elseifs.taskands.task:has_errors()then-- don't continue tasks if there are errors--- 如果遇到 “wait” 类型的任务,并且不在恢复状态,则增加 waiting 计数elseifstepandstep.task=="wait"andnotresumethen-- waiting for syncwaiting=waiting+1wait_step=s.step--- 否则,将任务加入到 next 列表中,准备执行下一个任务elsenext[#next+1]=nameendend--- 遍历 next 列表中的插件名称,调度和执行下一个任务-- schedule next tasksfor_,nameinipairs(next)do--- 检查并发限制,确保不会同时运行超过指定数量的任务。ifself._opts.concurrencyandactive>=self._opts.concurrencythenbreakendlocals=state[name]localplugin=self:plugin(name)whiles.step<=#self._pipelinedoifs.step==#self._pipelinethen-- dones.task=nilplugin._.working=falsebreakelseifs.step<#self._pipelinethen-- nexts.step=s.step+1localstep=self._pipeline[s.step]ifstep.task=="wait"thenplugin._.working=falsewaiting=waiting+1wait_step=s.stepbreakelses.task=self:queue(plugin,step)plugin._.working=trueifs.taskthenactive=active+1s.task:wake(false)breakendendendendendend