diff --git a/lua/core/utils.lua b/lua/core/utils.lua index d95cb92..56e64a4 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -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 diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 9a4eeda..7a9bfcb 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -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) - end - end) + for _, v in pairs(plugins) do + packer.use(v) + end end