From 904f9df637c5d2768285ac3dc99caebea0c5c24e Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Mon, 20 Sep 2021 20:35:14 +0600 Subject: [PATCH] refactor: replace rtp_searcher with nvim_get_runtime_file (#65) --- lua/lualine/utils/loader.lua | 4 ++-- lua/lualine_require.lua | 17 ++--------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua index ef9d159..d8e5547 100644 --- a/lua/lualine/utils/loader.lua +++ b/lua/lualine/utils/loader.lua @@ -224,8 +224,8 @@ end local function load_theme(theme_name) assert(is_valid_filename(theme_name), 'Invalid filename') local retval - local path = table.concat({ 'lua', 'lualine', 'themes', theme_name }, sep) .. '.lua' - local files = lualine_require.rtp_searcher(path) + local path = table.concat { 'lua/lualine/themes/', theme_name, '.lua' } + local files = vim.api.nvim_get_runtime_file(path, true) local n_files = #files if n_files == 0 then -- No match found diff --git a/lua/lualine_require.lua b/lua/lualine_require.lua index 4d86887..6aa35f7 100644 --- a/lua/lualine_require.lua +++ b/lua/lualine_require.lua @@ -35,7 +35,8 @@ function M.require(module) end end - local paths = M.rtp_searcher('lua' .. M.sep .. pattern, true) + pattern = table.concat { 'lua/', module:gsub('%.', '/'), '.lua' } + local paths = vim.api.nvim_get_runtime_file(pattern, false) if #paths > 0 then local mod_result = dofile(paths[1]) package.loaded[module] = mod_result @@ -45,20 +46,6 @@ function M.require(module) return require(module) end -function M.rtp_searcher(file, once) - local ret = {} - for _, dir in ipairs(vim.api.nvim_list_runtime_paths()) do - local path = dir .. M.sep .. file - if vim.loop.fs_stat(path) then - ret[#ret + 1] = path - if once then - break - end - end - end - return ret -end - function M.lazy_require(modules) return setmetatable({}, { __index = function(self, key)