Skip to content

Commit fe6d0b1

Browse files
committed
feat: task docs and options for logs
1 parent 6f835ab commit fe6d0b1

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

lua/lazy/manager.lua

+23-4
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,20 @@ function M.run(operation, opts, filter)
4949
runner:wait(function()
5050
-- check if we need to do any post-install hooks
5151
for _, plugin in ipairs(runner:plugins()) do
52-
if plugin.dirty and (plugin.opt == false or plugin.run) then
53-
runner:add(Task.new(plugin, "run"))
52+
if plugin.dirty then
53+
runner:add(Task.new(plugin, "docs"))
54+
if plugin.opt == false or plugin.run then
55+
runner:add(Task.new(plugin, "run"))
56+
end
5457
end
5558
plugin.dirty = false
56-
if operation == "update" then
57-
runner:add(Task.new(plugin, "log"))
59+
if opts.show and operation == "update" and plugin.updated and plugin.updated.from ~= plugin.updated.to then
60+
runner:add(Task.new(plugin, "log", {
61+
log = {
62+
from = plugin.updated.from,
63+
to = plugin.updated.to,
64+
},
65+
}))
5866
end
5967
end
6068
-- wait for post-install to finish
@@ -96,6 +104,14 @@ function M.log(opts)
96104
end)
97105
end
98106

107+
---@param opts? ManagerOpts
108+
function M.docs(opts)
109+
---@param plugin LazyPlugin
110+
M.run("docs", opts, function(plugin)
111+
return plugin.installed
112+
end)
113+
end
114+
99115
---@param opts? ManagerOpts
100116
function M.clean(opts)
101117
opts = opts or {}
@@ -133,6 +149,8 @@ end
133149

134150
function M.clear()
135151
for _, plugin in pairs(Config.plugins) do
152+
-- clear updated status
153+
plugin.updated = nil
136154
-- clear finished tasks
137155
if plugin.tasks then
138156
---@param task LazyTask
@@ -142,6 +160,7 @@ function M.clear()
142160
end
143161
end
144162
M.to_clean = {}
163+
vim.cmd([[do User LazyRender]])
145164
end
146165

147166
return M

lua/lazy/task.lua

+40-6
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,30 @@ local Util = require("lazy.core.util")
66
---@field plugin LazyPlugin
77
---@field type TaskType
88
---@field running boolean
9+
---@field opts TaskOptions
910
local Task = {}
1011

11-
---@alias TaskType "update"|"install"|"run"|"clean"|"log"
12+
---@alias TaskType "update"|"install"|"run"|"clean"|"log"|"docs"
13+
14+
---@class TaskOptions
15+
local options = {
16+
log = {
17+
since = "7 days ago",
18+
---@type string
19+
from = nil,
20+
---@type string
21+
to = nil,
22+
},
23+
}
1224

1325
---@param plugin LazyPlugin
1426
---@param type TaskType
15-
function Task.new(plugin, type)
27+
---@param opts? TaskOptions
28+
function Task.new(plugin, type, opts)
1629
local self = setmetatable({}, {
1730
__index = Task,
1831
})
32+
self.opts = vim.tbl_deep_extend("force", {}, options, opts or {})
1933
self.plugin = plugin
2034
self.type = type
2135
self.output = ""
@@ -94,7 +108,7 @@ function Task:install()
94108
end
95109

96110
function Task:run()
97-
Loader.load(self.plugin)
111+
Loader.load(self.plugin, { task = "run" })
98112

99113
local run = self.plugin.run
100114
if run then
@@ -115,6 +129,14 @@ function Task:run()
115129
self:_done()
116130
end
117131

132+
function Task:docs()
133+
local docs = self.plugin.dir .. "/doc/"
134+
if Util.file_exists(docs) then
135+
self.output = vim.api.nvim_cmd({ cmd = "helptags", args = { docs } }, { output = true })
136+
end
137+
self:_done()
138+
end
139+
118140
---@param cmd string
119141
---@param opts ProcessOpts
120142
function Task:spawn(cmd, opts)
@@ -162,6 +184,8 @@ function Task:start()
162184
self:clean()
163185
elseif self.type == "log" then
164186
self:log()
187+
elseif self.type == "docs" then
188+
self:docs()
165189
end
166190
end)
167191

@@ -184,8 +208,14 @@ function Task:log()
184208
"--decorate",
185209
"--date=short",
186210
"--color=never",
187-
"--since='7 days ago'",
188211
}
212+
213+
if self.opts.log.from then
214+
table.insert(args, self.opts.log.from .. ".." .. (self.opts.log.to or "HEAD"))
215+
else
216+
table.insert(args, "--since=" .. self.opts.log.since)
217+
end
218+
189219
self:spawn("git", {
190220
args = args,
191221
cwd = self.plugin.dir,
@@ -209,14 +239,18 @@ function Task:update()
209239
"--update-shallow",
210240
"--progress",
211241
}
212-
local git = Util.git_info(self.plugin.dir)
242+
local git = assert(Util.git_info(self.plugin.dir))
213243

214244
self:spawn("git", {
215245
args = args,
216246
cwd = self.plugin.dir,
217247
on_exit = function(ok)
218248
if ok then
219-
local git_new = Util.git_info(self.plugin.dir)
249+
local git_new = assert(Util.git_info(self.plugin.dir))
250+
self.plugin.updated = {
251+
from = git.hash,
252+
to = git_new.hash,
253+
}
220254
self.plugin.dirty = not vim.deep_equal(git, git_new)
221255
end
222256
end,

0 commit comments

Comments
 (0)