From f95d1108d32aea730cf167d97637802c337c2bc5 Mon Sep 17 00:00:00 2001 From: Sumi-Sumi Date: Sat, 12 Aug 2023 18:38:07 +0900 Subject: [PATCH] feat(utils): add `load_config()` to resolve and load `user.configs` --- lua/core/pack.lua | 11 +---------- lua/modules/utils/init.lua | 9 ++++++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lua/core/pack.lua b/lua/core/pack.lua index 8015489e7..973a91775 100644 --- a/lua/core/pack.lua +++ b/lua/core/pack.lua @@ -26,15 +26,6 @@ function Lazy:load_plugins() local append_nativertp = function() package.path = package.path .. string.format(";%s;%s", modules_dir .. "/configs/?.lua", modules_dir .. "/configs/?/init.lua") - table.insert(package.loaders, function(modulename) - local modulepath = user_config_dir .. "/configs/" .. modulename:gsub("%.", "/") .. ".lua" - local filename = modulepath:gsub("%?", modulepath) - local file = io.open(filename, "rb") - if file then - return assert(load(assert(file:read("*a")), filename)) - end - return string.format("\n\tno file '%s' (checked with custom loader)", filename) - end) end local get_plugins_list = function() @@ -140,4 +131,4 @@ function Lazy:load_lazy() require("lazy").setup(self.modules, lazy_settings) end -Lazy:load_lazy() +Lazy:load_lazy() \ No newline at end of file diff --git a/lua/modules/utils/init.lua b/lua/modules/utils/init.lua index 185ebb0df..99a462818 100644 --- a/lua/modules/utils/init.lua +++ b/lua/modules/utils/init.lua @@ -281,6 +281,13 @@ function M.extend_config(config, user_config) return config end +---@param modname string @Module name of the config +---@return unknown +---@return unknown @Loader data +M.load_config = function(modname) + return require("user.configs." .. modname) +end + ---@param plugin_name string @Module name of the plugin (used to setup itself) ---@param opts nil|table @The default config to be merged with ---@param vim_plugin? boolean @If this plugin is a vimscript one @@ -349,4 +356,4 @@ We received a `%s` for plugin <%s>.]], end end -return M +return M \ No newline at end of file