mirror of https://github.com/folke/lazy.nvim.git
feat: return wether a module was loaded from cache or from file (dirty)
This commit is contained in:
parent
7f17de34fd
commit
38e2711cdb
|
@ -11,7 +11,7 @@ end
|
||||||
|
|
||||||
---@param modname string
|
---@param modname string
|
||||||
---@param modpath string
|
---@param modpath string
|
||||||
---@return table
|
---@return any, boolean
|
||||||
function M.load(modname, modpath)
|
function M.load(modname, modpath)
|
||||||
local err
|
local err
|
||||||
---@type (string|fun())?
|
---@type (string|fun())?
|
||||||
|
@ -24,8 +24,10 @@ function M.load(modname, modpath)
|
||||||
chunk = nil
|
chunk = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cached = false
|
||||||
if chunk then
|
if chunk then
|
||||||
chunk, err = loadstring(chunk --[[@as string]], "@" .. modpath)
|
cached = true
|
||||||
|
chunk, err = load(chunk --[[@as string]], "@" .. modpath, "b")
|
||||||
else
|
else
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.notify("loadfile(" .. modname .. ")")
|
vim.notify("loadfile(" .. modname .. ")")
|
||||||
|
@ -37,9 +39,7 @@ function M.load(modname, modpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
if chunk then
|
if chunk then
|
||||||
---@diagnostic disable-next-line: no-unknown
|
return chunk(), cached
|
||||||
package.loaded[modname] = chunk()
|
|
||||||
return package.loaded[modname]
|
|
||||||
else
|
else
|
||||||
error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
|
@ -54,7 +54,7 @@ function M.setup()
|
||||||
|
|
||||||
-- preload core modules
|
-- preload core modules
|
||||||
local root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h:h")
|
local root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h:h")
|
||||||
for _, name in ipairs({ "util", "config", "loader", "state", "plugin" }) do
|
for _, name in ipairs({ "util", "config", "loader", "plugin" }) do
|
||||||
local modname = "lazy.core." .. name
|
local modname = "lazy.core." .. name
|
||||||
---@diagnostic disable-next-line: no-unknown
|
---@diagnostic disable-next-line: no-unknown
|
||||||
package.preload[modname] = function()
|
package.preload[modname] = function()
|
||||||
|
|
Loading…
Reference in New Issue