From 0044d37d5ea364df787671247d72e21dba2578de Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 4 Oct 2022 09:47:48 +0200 Subject: [PATCH] fix: added check in lazy loader if module exists #2 --- lua/noice/hacks.lua | 4 ++-- lua/noice/util/lazy.lua | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/noice/hacks.lua b/lua/noice/hacks.lua index 61e3e265..dd73fbf0 100644 --- a/lua/noice/hacks.lua +++ b/lua/noice/hacks.lua @@ -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 diff --git a/lua/noice/util/lazy.lua b/lua/noice/util/lazy.lua index 735d6117..6a7efa02 100644 --- a/lua/noice/util/lazy.lua +++ b/lua/noice/util/lazy.lua @@ -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,