Skip to content

Commit a36d506

Browse files
committed
feat(manage): added user events when operations finish. Fixes #135
1 parent 3352fc6 commit a36d506

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,18 @@ require("lualine").setup({
519519

520520
</details>
521521

522+
### 📆 User Events
523+
524+
The following user events will be triggered:
525+
526+
- **LazyDone**: when lazy has finished starting up and loaded your config
527+
- **LazySync**: after running sync
528+
- **LazyInstall**: after an install
529+
- **LazyUpdate**: after an update
530+
- **LazyClean**: after a clean
531+
- **LazyCheck**: after checking for updates
532+
- **LazyLog**: after running log
533+
522534
## 🔒 Lockfile `lazy-lock.json`
523535

524536
After every **update**, the local lockfile is updated with the installed revisions.

TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
- [ ] package meta index (package.lua cache for all packages)
4646

4747
- [ ] document highlight groups
48-
- [ ] document user events
48+
- [x] document user events
4949
- [ ] document API, like lazy.plugins()
5050
- [ ] icons
5151

lua/lazy/manage/init.lua

+21-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ function M.run(ropts, opts)
4848
vim.cmd([[do User LazyRender]])
4949
Plugin.update_state()
5050
require("lazy.manage.checker").fast_check({ report = false })
51+
local mode = opts.mode
52+
if mode then
53+
vim.cmd("do User Lazy" .. mode:sub(1, 1):upper() .. mode:sub(2))
54+
end
5155
end)
5256

5357
if opts.wait then
@@ -141,14 +145,27 @@ end
141145

142146
---@param opts? ManagerOpts
143147
function M.sync(opts)
144-
opts = M.opts(opts, { mode = "sync" })
148+
opts = M.opts(opts)
145149
if opts.clear then
146150
M.clear()
147151
opts.clear = false
148152
end
149-
M.clean(opts)
150-
M.install(opts)
151-
M.update(opts)
153+
if opts.show ~= false then
154+
vim.schedule(function()
155+
require("lazy.view").show("sync")
156+
end)
157+
opts.show = false
158+
end
159+
local clean = M.clean(opts)
160+
local install = M.install(opts)
161+
local update = M.update(opts)
162+
clean:wait(function()
163+
install:wait(function()
164+
update:wait(function()
165+
vim.cmd([[do User LazySync]])
166+
end)
167+
end)
168+
end)
152169
end
153170

154171
---@param opts? ManagerOpts

lua/lazy/manage/runner.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ end
139139
---@param cb? fun()
140140
function Runner:wait(cb)
141141
if #self._running == 0 then
142-
return cb and cb()
142+
if cb then
143+
cb()
144+
end
145+
return self
143146
end
144147

145148
if cb then
@@ -150,6 +153,7 @@ function Runner:wait(cb)
150153
vim.wait(10)
151154
end
152155
end
156+
return self
153157
end
154158

155159
return Runner

0 commit comments

Comments
 (0)