feat(loaders): Allow alt loaders like fnl or tl

I'm playing with https://github.com/folke/lazy.nvim/issues/978

So here's the thing. This is working for me, but I'm not 100% sure of
why it's working. It's not hitting *most* of the code I touched since I
didn't modify anything to touch that code. It is my suspicion that what
I've done is make lazy.nvim more flexible at the cost of breaking
LazyVim, which I don't use. So now I think the best course of action is
to pull LazyVim and configure it to use this alternate loaders code to
see how it falls over
This commit is contained in:
FlexFoot 2023-08-07 18:05:59 -04:00
commit 28f79093c5

View file

@ -201,18 +201,49 @@ function M.walk(path, fn)
end) end)
end end
---@param delim string
function string:split(delim)
-- This default doesn't fully make sense, but I'm just replicating some python functionality
delim = delim or '%.'
if self:sub(-#delim ~= delim) then
self = self .. delim
end
return self:gmatch('(.-)' .. delim:gsub("[()%%.[^$%]*+%-?]", "%%%1"))
end
---@param value any
function table:contains(value)
for _, element in ipairs(self) do
if element == value then
return true
end
end
return false
end
---@param root string ---@param root string
---@param fn fun(modname:string, modpath:string) ---@param fn fun(modname:string, modpath:string)
---@param modname? string -- @param optionals? {modname:str, extensions:str[]}
function M.walkmods(root, fn, modname) function M.walkmods(root, fn, optionals)
modname = modname and (modname:gsub("%.$", "") .. ".") or "" optionals.modname = optionals.modname and (optionals.modname:gsub("%.$", "") .. ".") or ""
if not optionals.extensions:contains("lua") then
table.insert(optionals.extensions, "lua")
end
M.ls(root, function(path, name, type) M.ls(root, function(path, name, type)
local name_components = name.split("%.")
local extension = name_components[#name_components]
if name == "init.lua" then if name == "init.lua" then
fn(modname:gsub("%.$", ""), path) fn(optionals.modname:gsub("%.$", ""), path)
elseif (type == "file" or type == "link") and name:sub(-4) == ".lua" then elseif (type == "file" or type == "link") and (optionals.extensions:contains(extension)) then
fn(modname .. name:sub(1, -5), path) table.remove(name_components[#name_components])
fn(optionals.modname .. table.concat(name_components, ".", path))
elseif type == "directory" then elseif type == "directory" then
M.walkmods(path, fn, modname .. name .. ".") M.walkmods(path, fn, {
modname = optionals.modname .. name .. ".", extensions = optionals.extensions
})
end end
end) end)
end end