mirror of https://github.com/folke/lazy.nvim.git
perf(plugin): minor optim to resolve imports a bit faster
This commit is contained in:
parent
1fad61712b
commit
a9d7ade203
|
@ -150,8 +150,11 @@ function Spec:import(spec)
|
||||||
local modspecs = {}
|
local modspecs = {}
|
||||||
|
|
||||||
if type(import) == "string" then
|
if type(import) == "string" then
|
||||||
Util.lsmod(import, function(modname)
|
Util.lsmod(import, function(modname, modpath)
|
||||||
modspecs[#modspecs + 1] = modname
|
modspecs[#modspecs + 1] = modname
|
||||||
|
package.preload[modname] = function()
|
||||||
|
return loadfile(modpath)()
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
table.sort(modspecs)
|
table.sort(modspecs)
|
||||||
else
|
else
|
||||||
|
|
|
@ -287,7 +287,7 @@ function M.find_root(modname)
|
||||||
local ret = require("lazy.core.cache").find(modname, {
|
local ret = require("lazy.core.cache").find(modname, {
|
||||||
rtp = true,
|
rtp = true,
|
||||||
paths = paths,
|
paths = paths,
|
||||||
patterns = { "", ".lua" },
|
patterns = { ".lua", "" },
|
||||||
})[1]
|
})[1]
|
||||||
|
|
||||||
if not ret and cached then
|
if not ret and cached then
|
||||||
|
@ -295,25 +295,27 @@ function M.find_root(modname)
|
||||||
ret = require("lazy.core.cache").find(modname, {
|
ret = require("lazy.core.cache").find(modname, {
|
||||||
rtp = false,
|
rtp = false,
|
||||||
paths = paths,
|
paths = paths,
|
||||||
patterns = { "", ".lua" },
|
patterns = { ".lua", "" },
|
||||||
})[1]
|
})[1]
|
||||||
end
|
end
|
||||||
if ret then
|
if ret then
|
||||||
local root = ret.modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")
|
return ret.modpath:gsub("%.lua$", ""), ret.modpath
|
||||||
return root
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param modname string
|
---@param modname string
|
||||||
---@param fn fun(modname:string, modpath:string)
|
---@param fn fun(modname:string, modpath:string)
|
||||||
function M.lsmod(modname, fn)
|
function M.lsmod(modname, fn)
|
||||||
local root = M.find_root(modname)
|
local root, match = M.find_root(modname)
|
||||||
if not root then
|
if not root then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.uv.fs_stat(root .. ".lua") then
|
if match:sub(-4) == ".lua" then
|
||||||
fn(modname, root .. ".lua")
|
fn(modname, match)
|
||||||
|
if not vim.uv.fs_stat(root) then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.ls(root, function(path, name, type)
|
M.ls(root, function(path, name, type)
|
||||||
|
|
Loading…
Reference in New Issue