fix(util): ensure unique cache keys in LazyVim.memoize

This commit is contained in:
Aofei Sheng 2024-06-11 08:47:24 +08:00
parent 7d30360df2
commit 00be797787

View file

@ -274,8 +274,10 @@ local cache = {} ---@type table<string, any>
---@param fn T
---@return T
function M.memoize(fn)
local info = debug.getinfo(fn, "S")
local keyprefix = info.source .. ":" .. info.linedefined .. ":"
return function(...)
local key = vim.inspect({ ... })
local key = keyprefix .. vim.inspect({ ... })
if cache[key] == nil then
cache[key] = fn(...)
end