@@ -15,6 +15,8 @@ M.types = {
15
15
16
16
--- @type table<LoaderType , table<string , string[]>> |{ init : string[] }
17
17
M .loaders = nil
18
+ --- @type LazyPlugin[]
19
+ M .loading = {}
18
20
19
21
--- @param plugin LazyPlugin
20
22
function M .add (plugin )
@@ -59,7 +61,7 @@ function M.setup()
59
61
Util .track (" loader_events" )
60
62
for event , plugins in pairs (M .loaders .event ) do
61
63
if event == " VimEnter" and vim .v .vim_did_enter == 1 then
62
- M .load (plugins )
64
+ M .load (plugins , { event = event } )
63
65
else
64
66
local user_event = event :match (" User (.*)" )
65
67
vim .api .nvim_create_autocmd (user_event and " User" or event , {
@@ -68,7 +70,7 @@ function M.setup()
68
70
pattern = user_event ,
69
71
callback = function ()
70
72
Util .track (" event: " .. (user_event or event ))
71
- M .load (plugins )
73
+ M .load (plugins , { event = event } )
72
74
Util .track ()
73
75
end ,
74
76
})
@@ -85,7 +87,7 @@ function M.setup()
85
87
group = group ,
86
88
callback = function ()
87
89
Util .track (" filetype: " .. ft )
88
- M .load (plugins )
90
+ M .load (plugins , { ft = ft } )
89
91
Util .track ()
90
92
end ,
91
93
})
@@ -98,7 +100,7 @@ function M.setup()
98
100
vim .keymap .set (" n" , keys , function ()
99
101
vim .keymap .del (" n" , keys )
100
102
Util .track (" keys: " .. keys )
101
- M .load (plugins )
103
+ M .load (plugins , { keys = keys } )
102
104
vim .api .nvim_input (keys )
103
105
Util .track ()
104
106
end )
@@ -140,7 +142,7 @@ function M.init_plugins()
140
142
Util .track ()
141
143
end
142
144
if plugin .opt == false then
143
- M .load (plugin )
145
+ M .load (plugin , { package = " start " } )
144
146
end
145
147
end
146
148
Util .track ()
@@ -154,7 +156,21 @@ function M.module(modname)
154
156
local name = modname :sub (1 , idx - 1 )
155
157
local plugins = M .loaders .module [name ]
156
158
if plugins then
157
- M .load (plugins )
159
+ local reason = { require = modname }
160
+ if # M .loading == 0 then
161
+ local f = 3
162
+ while not reason .source do
163
+ local info = debug.getinfo (f , " S" )
164
+ f = f + 1
165
+ if not info then
166
+ break
167
+ end
168
+ if info .what ~= " C" then
169
+ reason .source = info .source :sub (2 )
170
+ end
171
+ end
172
+ end
173
+ M .load (plugins , reason )
158
174
-- M.loaders.module[name] = nil
159
175
end
160
176
idx = modname :find (" ." , idx + 1 , true )
@@ -170,7 +186,8 @@ function M.module(modname)
170
186
end
171
187
172
188
--- @param plugins string | LazyPlugin | string[] | LazyPlugin[]
173
- function M .load (plugins )
189
+ --- @param reason { [string] : string }
190
+ function M .load (plugins , reason )
174
191
if type (plugins ) == " string" or plugins .name then
175
192
--- @diagnostic disable-next-line : assign-type-mismatch
176
193
plugins = { plugins }
@@ -183,20 +200,26 @@ function M.load(plugins)
183
200
end
184
201
185
202
if not plugin .loaded then
186
- plugin .loaded = true
203
+ plugin .loaded = vim .deepcopy (reason or {})
204
+ if # M .loading > 0 then
205
+ plugin .loaded .plugin = M .loading [# M .loading ].name
206
+ end
207
+
208
+ table.insert (M .loading , plugin )
187
209
188
210
Util .track (plugin .name )
189
211
M .packadd (plugin )
190
212
191
213
if plugin .requires then
192
- M .load (plugin .requires )
214
+ M .load (plugin .requires , {} )
193
215
end
194
216
195
217
if plugin .config then
196
218
plugin .config ()
197
219
end
198
220
199
- Util .track ()
221
+ plugin .loaded .time = Util .track ().time
222
+ table.remove (M .loading )
200
223
vim .schedule (function ()
201
224
vim .cmd (" do User LazyRender" )
202
225
end )
0 commit comments