@@ -6,16 +6,30 @@ local Util = require("lazy.core.util")
6
6
--- @field plugin LazyPlugin
7
7
--- @field type TaskType
8
8
--- @field running boolean
9
+ --- @field opts TaskOptions
9
10
local Task = {}
10
11
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
+ }
12
24
13
25
--- @param plugin LazyPlugin
14
26
--- @param type TaskType
15
- function Task .new (plugin , type )
27
+ --- @param opts ? TaskOptions
28
+ function Task .new (plugin , type , opts )
16
29
local self = setmetatable ({}, {
17
30
__index = Task ,
18
31
})
32
+ self .opts = vim .tbl_deep_extend (" force" , {}, options , opts or {})
19
33
self .plugin = plugin
20
34
self .type = type
21
35
self .output = " "
@@ -94,7 +108,7 @@ function Task:install()
94
108
end
95
109
96
110
function Task :run ()
97
- Loader .load (self .plugin )
111
+ Loader .load (self .plugin , { task = " run " } )
98
112
99
113
local run = self .plugin .run
100
114
if run then
@@ -115,6 +129,14 @@ function Task:run()
115
129
self :_done ()
116
130
end
117
131
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
+
118
140
--- @param cmd string
119
141
--- @param opts ProcessOpts
120
142
function Task :spawn (cmd , opts )
@@ -162,6 +184,8 @@ function Task:start()
162
184
self :clean ()
163
185
elseif self .type == " log" then
164
186
self :log ()
187
+ elseif self .type == " docs" then
188
+ self :docs ()
165
189
end
166
190
end )
167
191
@@ -184,8 +208,14 @@ function Task:log()
184
208
" --decorate" ,
185
209
" --date=short" ,
186
210
" --color=never" ,
187
- " --since='7 days ago'" ,
188
211
}
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
+
189
219
self :spawn (" git" , {
190
220
args = args ,
191
221
cwd = self .plugin .dir ,
@@ -209,14 +239,18 @@ function Task:update()
209
239
" --update-shallow" ,
210
240
" --progress" ,
211
241
}
212
- local git = Util .git_info (self .plugin .dir )
242
+ local git = assert ( Util .git_info (self .plugin .dir ) )
213
243
214
244
self :spawn (" git" , {
215
245
args = args ,
216
246
cwd = self .plugin .dir ,
217
247
on_exit = function (ok )
218
248
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
+ }
220
254
self .plugin .dirty = not vim .deep_equal (git , git_new )
221
255
end
222
256
end ,
0 commit comments