Skip to content

Commit

Permalink
fix: added check in lazy loader if module exists #2
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 4, 2022
1 parent e362b85 commit 0044d37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lua/noice/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ function M.fix_cmp()
end
end

local ok, api = pcall(require, "cmp.utils.api")
if not ok then
local api = require("cmp.utils.api")
if not api.lazy_exists() then
-- cmp not availablle
return
end
Expand Down
6 changes: 5 additions & 1 deletion lua/noice/util/lazy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ return function(module)
-- if already loaded, return the module
-- otherwise return a lazy module
return type(package.loaded[module]) == "table" and package.loaded[module]
or setmetatable({}, {
or setmetatable({
lazy_exists = function()
return pcall(require, module) == true
end,
}, {
__index = function(_, key)
return require(module)[key]
end,
Expand Down

0 comments on commit 0044d37

Please sign in to comment.