Support old plugin syntax too | Cleanup | Misc

use vim.notify to give deprecation warning

    use packer.use directly rather than wrapping around packer.startup

    Do some explicit type checking

Co-authored-by: Akianonymus <anonymus.aki@gmail.com>
This commit is contained in:
siduck 2022-09-08 14:45:23 +05:30 committed by Sidhanth Rathod
parent d61946d3bf
commit e8a4158924
2 changed files with 45 additions and 12 deletions

View file

@ -101,12 +101,28 @@ end
-- merge default/user plugin tables
M.merge_plugins = function(default_plugins)
default_plugins = merge_tb("force", default_plugins, M.load_config().plugins)
local plugin_configs = M.load_config().plugins
local user_plugins = plugin_configs
-- old plugin syntax for adding plugins
if plugin_configs.user and type(plugin_configs.user) == "table" then
user_plugins = plugin_configs.user
end
-- support old plugin removal syntax
local remove_plugins = plugin_configs.remove
if type(remove_plugins) == "table" then
for _, v in ipairs(remove_plugins) do
default_plugins[v] = nil
end
end
default_plugins = merge_tb("force", default_plugins, user_plugins)
local final_table = {}
for key, val in pairs(default_plugins) do
if val then
if val and type(val) == "table" then
default_plugins[key][1] = key
final_table[#final_table + 1] = default_plugins[key]
end
@ -117,14 +133,27 @@ end
-- override plugin options table with custom ones
M.load_override = function(options_table, name)
local user_plugins = M.load_config().plugins
local plugin_options = {}
local plugin_configs, plugin_options = M.load_config().plugins, nil
if user_plugins[name] then
plugin_options = user_plugins[name].override_options or {}
plugin_options = type(plugin_options) == "table" and plugin_options or plugin_options()
-- support old plugin syntax for override
local user_override = plugin_configs.user and plugin_configs.user.override and plugin_configs.user.override[name]
if user_override and type(user_override) == "table" then
plugin_options = user_override
end
-- if no old style plugin override is found, then use the new syntax
if not plugin_options and plugin_configs[name] then
local override_options = plugin_configs[name].override_options or {}
if type(override_options) == "table" then
plugin_options = override_options
elseif type(override_options) == "function" then
plugin_options = override_options()
end
end
-- make sure the plugin options are a table
plugin_options = type(plugin_options) == "table" and plugin_options or {}
return merge_tb("force", options_table, plugin_options)
end
@ -160,6 +189,12 @@ M.packer_sync = function(...)
if packer_exists then
packer.sync(...)
local plugins = M.load_config().plugins
local old_style_options = plugins.user or plugins.override or plugins.remove
if old_style_options then
vim.notify_once({ "NvChad: This plugin syntax is deprecated, use new style config." }, "Error")
end
else
error "Packer could not be loaded!"
end

View file

@ -219,9 +219,7 @@ if present then
init_options = require("core.utils").load_override(init_options, "wbthomason/packer.nvim")
packer.init(init_options)
packer.startup(function(use)
for _, v in pairs(plugins) do
use(v)
packer.use(v)
end
end)
end