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:
parent
d61946d3bf
commit
e8a4158924
|
@ -101,12 +101,28 @@ end
|
||||||
|
|
||||||
-- merge default/user plugin tables
|
-- merge default/user plugin tables
|
||||||
M.merge_plugins = function(default_plugins)
|
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 = {}
|
local final_table = {}
|
||||||
|
|
||||||
for key, val in pairs(default_plugins) do
|
for key, val in pairs(default_plugins) do
|
||||||
if val then
|
if val and type(val) == "table" then
|
||||||
default_plugins[key][1] = key
|
default_plugins[key][1] = key
|
||||||
final_table[#final_table + 1] = default_plugins[key]
|
final_table[#final_table + 1] = default_plugins[key]
|
||||||
end
|
end
|
||||||
|
@ -117,14 +133,27 @@ end
|
||||||
|
|
||||||
-- override plugin options table with custom ones
|
-- override plugin options table with custom ones
|
||||||
M.load_override = function(options_table, name)
|
M.load_override = function(options_table, name)
|
||||||
local user_plugins = M.load_config().plugins
|
local plugin_configs, plugin_options = M.load_config().plugins, nil
|
||||||
local plugin_options = {}
|
|
||||||
|
|
||||||
if user_plugins[name] then
|
-- support old plugin syntax for override
|
||||||
plugin_options = user_plugins[name].override_options or {}
|
local user_override = plugin_configs.user and plugin_configs.user.override and plugin_configs.user.override[name]
|
||||||
plugin_options = type(plugin_options) == "table" and plugin_options or plugin_options()
|
if user_override and type(user_override) == "table" then
|
||||||
|
plugin_options = user_override
|
||||||
end
|
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)
|
return merge_tb("force", options_table, plugin_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -160,6 +189,12 @@ M.packer_sync = function(...)
|
||||||
|
|
||||||
if packer_exists then
|
if packer_exists then
|
||||||
packer.sync(...)
|
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
|
else
|
||||||
error "Packer could not be loaded!"
|
error "Packer could not be loaded!"
|
||||||
end
|
end
|
||||||
|
|
|
@ -219,9 +219,7 @@ if present then
|
||||||
init_options = require("core.utils").load_override(init_options, "wbthomason/packer.nvim")
|
init_options = require("core.utils").load_override(init_options, "wbthomason/packer.nvim")
|
||||||
packer.init(init_options)
|
packer.init(init_options)
|
||||||
|
|
||||||
packer.startup(function(use)
|
|
||||||
for _, v in pairs(plugins) do
|
for _, v in pairs(plugins) do
|
||||||
use(v)
|
packer.use(v)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue