Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): fix merged user routers configs #158

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions lua/gitlinker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,33 @@
--- @return table<string, {list_routers:table,map_routers:table}>
local function _merge_routers(opts)
local result = {}
-- default routers
-- default_router_type: browse, blame, etc

-- users list
if type(opts.router) == "table" then
-- user_router_type: browse, blame, etc
for user_router_type, user_router_bindings in pairs(opts.router) do
if result[user_router_type] == nil then
result[user_router_type] = {}
result[user_router_type].list_routers = {}
result[user_router_type].map_routers = {}
end
-- list
for i, tuple in ipairs(user_router_bindings) do
if type(i) == "number" and type(tuple) == "table" and #tuple == 2 then
-- prepend to head for higher priority
table.insert(result[user_router_type].list_routers, 1, tuple)
end
end
end
end

-- default map
for default_router_type, default_router_bindings in pairs(Defaults.router) do
if result[default_router_type] == nil then
result[default_router_type] = {}
result[default_router_type].list_routers = {}
result[default_router_type].map_routers = {}
end
-- list
for i, tuple in ipairs(default_router_bindings) do
if type(i) == "number" and type(tuple) == "table" and #tuple == 2 then
table.insert(result[default_router_type].list_routers, tuple)
end
end
-- map
for pattern, route in pairs(default_router_bindings) do
if result[default_router_type].map_routers == nil then
Expand All @@ -443,21 +456,20 @@
end
end
end

-- default list
for default_router_type, default_router_bindings in pairs(Defaults.router) do
-- list
for i, tuple in ipairs(default_router_bindings) do
if type(i) == "number" and type(tuple) == "table" and #tuple == 2 then
table.insert(result[default_router_type].list_routers, tuple)

Check warning on line 465 in lua/gitlinker.lua

View check run for this annotation

Codecov / codecov/patch

lua/gitlinker.lua#L464-L465

Added lines #L464 - L465 were not covered by tests
end
end
end

-- user map
if type(opts.router) == "table" then
-- user_router_type: browse, blame, etc
for user_router_type, user_router_bindings in pairs(opts.router) do
if result[user_router_type] == nil then
result[user_router_type] = {}
result[user_router_type].list_routers = {}
result[user_router_type].map_routers = {}
end
-- list
for i, tuple in ipairs(user_router_bindings) do
if type(i) == "number" and type(tuple) == "table" and #tuple == 2 then
-- prepend to head for higher priority
table.insert(result[user_router_type].list_routers, 1, tuple)
end
end
-- map
for pattern, route in pairs(user_router_bindings) do
if result[user_router_type].map_routers == nil then
Expand Down
Loading