refactor: replace rtp_searcher with nvim_get_runtime_file (#65)

This commit is contained in:
shadmansaleh 2021-09-20 20:35:14 +06:00
parent aea5d8b90c
commit 904f9df637
2 changed files with 4 additions and 17 deletions

View File

@ -224,8 +224,8 @@ end
local function load_theme(theme_name) local function load_theme(theme_name)
assert(is_valid_filename(theme_name), 'Invalid filename') assert(is_valid_filename(theme_name), 'Invalid filename')
local retval local retval
local path = table.concat({ 'lua', 'lualine', 'themes', theme_name }, sep) .. '.lua' local path = table.concat { 'lua/lualine/themes/', theme_name, '.lua' }
local files = lualine_require.rtp_searcher(path) local files = vim.api.nvim_get_runtime_file(path, true)
local n_files = #files local n_files = #files
if n_files == 0 then if n_files == 0 then
-- No match found -- No match found

View File

@ -35,7 +35,8 @@ function M.require(module)
end end
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 if #paths > 0 then
local mod_result = dofile(paths[1]) local mod_result = dofile(paths[1])
package.loaded[module] = mod_result package.loaded[module] = mod_result
@ -45,20 +46,6 @@ function M.require(module)
return require(module) return require(module)
end 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) function M.lazy_require(modules)
return setmetatable({}, { return setmetatable({}, {
__index = function(self, key) __index = function(self, key)