fix(loader): show proper error message when trying to load a plugin that is not installed. Fixes #201. Fixes #202

This commit is contained in:
Folke Lemaitre 2022-12-28 17:56:20 +01:00
parent 5f423b29c6
commit 956164d27d
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 60 additions and 53 deletions

View File

@ -131,25 +131,34 @@ function M.load(plugins, reason)
---@cast plugins (string|LazyPlugin)[] ---@cast plugins (string|LazyPlugin)[]
for _, plugin in pairs(plugins) do for _, plugin in pairs(plugins) do
local try_load = true
if type(plugin) == "string" then if type(plugin) == "string" then
if not Config.plugins[plugin] then if Config.plugins[plugin] then
Util.error("Plugin " .. plugin .. " not found")
try_load = false
else
plugin = Config.plugins[plugin] plugin = Config.plugins[plugin]
else
Util.error("Plugin " .. plugin .. " not found")
plugin = nil
end
end
if plugin and not plugin._.loaded then
M._load(plugin, reason)
end
end end
end end
if try_load and plugin.cond then ---@param plugin LazyPlugin
try_load = plugin.cond == true or (type(plugin.cond) == "function" and plugin.cond()) or false ---@param reason {[string]:string}
plugin._.cond = try_load function M._load(plugin, reason)
if not plugin._.installed then
return Util.error("Plugin " .. plugin.name .. " is not installed")
end end
---@cast plugin LazyPlugin if plugin.cond ~= nil then
if plugin.cond == false or (type(plugin.cond) == "function" and not plugin.cond()) then
plugin._.cond = false
return
end
end
if try_load and not plugin._.loaded then
---@diagnostic disable-next-line: assign-type-mismatch ---@diagnostic disable-next-line: assign-type-mismatch
plugin._.loaded = {} plugin._.loaded = {}
for k, v in pairs(reason) do for k, v in pairs(reason) do
@ -189,8 +198,6 @@ function M.load(plugins, reason)
vim.cmd("do User LazyRender") vim.cmd("do User LazyRender")
end) end)
end end
end
end
--- runs plugin config --- runs plugin config
---@param plugin LazyPlugin ---@param plugin LazyPlugin