Skip to content

Commit 38e2711

Browse files
committed
feat: return wether a module was loaded from cache or from file (dirty)
1 parent 7f17de3 commit 38e2711

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lua/lazy/core/module.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ end
1111

1212
---@param modname string
1313
---@param modpath string
14-
---@return table
14+
---@return any, boolean
1515
function M.load(modname, modpath)
1616
local err
1717
---@type (string|fun())?
@@ -24,8 +24,10 @@ function M.load(modname, modpath)
2424
chunk = nil
2525
end
2626

27+
local cached = false
2728
if chunk then
28-
chunk, err = loadstring(chunk --[[@as string]], "@" .. modpath)
29+
cached = true
30+
chunk, err = load(chunk --[[@as string]], "@" .. modpath, "b")
2931
else
3032
vim.schedule(function()
3133
vim.notify("loadfile(" .. modname .. ")")
@@ -37,9 +39,7 @@ function M.load(modname, modpath)
3739
end
3840

3941
if chunk then
40-
---@diagnostic disable-next-line: no-unknown
41-
package.loaded[modname] = chunk()
42-
return package.loaded[modname]
42+
return chunk(), cached
4343
else
4444
error(err)
4545
end
@@ -54,7 +54,7 @@ function M.setup()
5454

5555
-- preload core modules
5656
local root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h:h")
57-
for _, name in ipairs({ "util", "config", "loader", "state", "plugin" }) do
57+
for _, name in ipairs({ "util", "config", "loader", "plugin" }) do
5858
local modname = "lazy.core." .. name
5959
---@diagnostic disable-next-line: no-unknown
6060
package.preload[modname] = function()

0 commit comments

Comments
 (0)