utils.lua: Improve plugin_list function

require strings if given, if succesfull then use that table
This commit is contained in:
Akianonymus 2022-05-05 13:40:25 +05:30 committed by siduck
parent 08e9ab363e
commit 382eb7c60e
1 changed files with 15 additions and 3 deletions

View File

@ -79,10 +79,24 @@ M.remove_default_plugins = function(plugins)
end end
-- merge default/user plugin tables -- merge default/user plugin tables
M.plugin_list = function(default_plugins) M.plugin_list = function(default_plugins)
local user_plugins = require("core.utils").load_config().plugins.user local user_plugins = require("core.utils").load_config().plugins.user
-- require if string is present
local ok
if type(user_plugins) == "string" then
ok, user_plugins = pcall(require, user_plugins)
if ok and not type(user_plugins) == "table" then
user_plugins = {}
end
end
if type(plug_override) == "string" then
ok, plug_override = pcall(require, plug_override)
if ok and not type(plug_override) == "table" then
plug_override = {}
end
end
-- merge default + user plugin table -- merge default + user plugin table
default_plugins = vim.tbl_deep_extend("force", default_plugins, user_plugins) default_plugins = vim.tbl_deep_extend("force", default_plugins, user_plugins)
@ -99,13 +113,11 @@ end
M.load_override = function(default_table, plugin_name) M.load_override = function(default_table, plugin_name)
local user_table = require("core.utils").load_config().plugins.override[plugin_name] local user_table = require("core.utils").load_config().plugins.override[plugin_name]
if type(user_table) == "table" then if type(user_table) == "table" then
default_table = vim.tbl_deep_extend("force", default_table, user_table) default_table = vim.tbl_deep_extend("force", default_table, user_table)
else else
default_table = default_table default_table = default_table
end end
return default_table return default_table
end end