Skip to content

Commit

Permalink
feat(manage): added user events when operations finish. Fixes #135
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 24, 2022
1 parent 3352fc6 commit a36d506
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,18 @@ require("lualine").setup({

</details>

### 📆 User Events

The following user events will be triggered:

- **LazyDone**: when lazy has finished starting up and loaded your config
- **LazySync**: after running sync
- **LazyInstall**: after an install
- **LazyUpdate**: after an update
- **LazyClean**: after a clean
- **LazyCheck**: after checking for updates
- **LazyLog**: after running log

## 🔒 Lockfile `lazy-lock.json`

After every **update**, the local lockfile is updated with the installed revisions.
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
- [ ] package meta index (package.lua cache for all packages)

- [ ] document highlight groups
- [ ] document user events
- [x] document user events
- [ ] document API, like lazy.plugins()
- [ ] icons

Expand Down
25 changes: 21 additions & 4 deletions lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function M.run(ropts, opts)
vim.cmd([[do User LazyRender]])
Plugin.update_state()
require("lazy.manage.checker").fast_check({ report = false })
local mode = opts.mode
if mode then
vim.cmd("do User Lazy" .. mode:sub(1, 1):upper() .. mode:sub(2))
end
end)

if opts.wait then
Expand Down Expand Up @@ -141,14 +145,27 @@ end

---@param opts? ManagerOpts
function M.sync(opts)
opts = M.opts(opts, { mode = "sync" })
opts = M.opts(opts)
if opts.clear then
M.clear()
opts.clear = false
end
M.clean(opts)
M.install(opts)
M.update(opts)
if opts.show ~= false then
vim.schedule(function()
require("lazy.view").show("sync")
end)
opts.show = false
end
local clean = M.clean(opts)
local install = M.install(opts)
local update = M.update(opts)
clean:wait(function()
install:wait(function()
update:wait(function()
vim.cmd([[do User LazySync]])
end)
end)
end)
end

---@param opts? ManagerOpts
Expand Down
6 changes: 5 additions & 1 deletion lua/lazy/manage/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ end
---@param cb? fun()
function Runner:wait(cb)
if #self._running == 0 then
return cb and cb()
if cb then
cb()
end
return self
end

if cb then
Expand All @@ -150,6 +153,7 @@ function Runner:wait(cb)
vim.wait(10)
end
end
return self
end

return Runner

0 comments on commit a36d506

Please sign in to comment.