@@ -52,8 +52,7 @@ function M.startup()
52
52
Util .track ({ start = " rtp plugins" })
53
53
for _ , path in ipairs (rtp ) do
54
54
if not path :find (" after/?$" ) then
55
- M .source_runtime (path , " plugin" )
56
- M .ftdetect (path )
55
+ M .packadd (path )
57
56
end
58
57
end
59
58
Util .track ()
@@ -83,6 +82,8 @@ function M.startup()
83
82
end
84
83
Util .track ()
85
84
85
+ M .init_done = true
86
+
86
87
-- run plugin init
87
88
Util .track ({ start = " init" })
88
89
for _ , plugin in pairs (Config .plugins ) do
@@ -94,7 +95,6 @@ function M.startup()
94
95
end
95
96
Util .track ()
96
97
97
- M .init_done = true
98
98
Util .track ()
99
99
end
100
100
@@ -180,33 +180,42 @@ end
180
180
-- This loader is added as the very last one.
181
181
-- This only hits when the modname is not cached and
182
182
-- even then only once per plugin. So pretty much never.
183
- --
184
- -- lazy.module will call this when loading a cached file with modpath set.
185
183
--- @param modname string
186
- --- @param modpath string ?
187
- function M .autoload (modname , modpath )
188
- -- fast return when we know the modpath
189
- if modpath then
190
- local plugin = require (" lazy.core.plugin" ).find (modpath )
191
- if plugin and not plugin ._ .loaded then
192
- M .load (plugin , { require = modname })
193
- end
194
- return
195
- end
184
+ function M .autoload (modname )
196
185
-- check if a lazy plugin should be loaded
197
186
for _ , plugin in pairs (Config .plugins ) do
198
187
if not plugin ._ .loaded then
199
188
for _ , pattern in ipairs ({ " .lua" , " /init.lua" }) do
200
189
local path = plugin .dir .. " /lua/" .. modname :gsub (" %." , " /" ) .. pattern
201
190
if vim .loop .fs_stat (path ) then
202
191
M .load (plugin , { require = modname })
192
+ -- check if the module has been loaded in the meantime
193
+ if type (package.loaded [modname ]) == " table" then
194
+ local mod = package.loaded [modname ]
195
+ return function ()
196
+ return mod
197
+ end
198
+ end
203
199
local chunk , err = loadfile (path )
204
200
return chunk or error (err )
205
201
end
206
202
end
207
203
end
208
204
end
209
- return modname .. " not found in unloaded opt plugins"
205
+ return modname .. " not found in lazy plugins"
206
+ end
207
+
208
+ -- lazy.cache will call this when loading a cached file with modpath set.
209
+ --- @param modname string
210
+ --- @param modpath string
211
+ function M .check_load (modname , modpath )
212
+ -- no need to check anything before init
213
+ if M .init_done then
214
+ local plugin = require (" lazy.core.plugin" ).find (modpath )
215
+ if plugin and not plugin ._ .loaded then
216
+ M .load (plugin , { require = modname })
217
+ end
218
+ end
210
219
end
211
220
212
221
return M
0 commit comments