Skip to content

Commit

Permalink
fix(duplicates): fix data shape (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: tris203 <[email protected]>
  • Loading branch information
tris203 and tris203 authored Dec 21, 2023
1 parent f400cb0 commit 683e163
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions lua/hawtkeys/duplicates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ function M.show_duplicates()
local allKeys = tsSearch.get_all_keymaps()
local duplicates = utils.find_duplicates(allKeys)
local resultTable = {}
for index, data in ipairs(duplicates) do
for index, data in pairs(duplicates) do
table.insert(resultTable, tostring(index) .. " duplicates found in ")
table.insert(
resultTable,
tostring(data[1][1].from_file)
.. ":"
.. tostring(data[2][1].from_file)
tostring(data[1].from_file) .. ":" .. tostring(data[2].from_file)
)
end
return resultTable
Expand Down
2 changes: 1 addition & 1 deletion lua/hawtkeys/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function M.find_duplicates(keymaps)
for _, v in pairs(keymaps) do
for _, v2 in pairs(keymaps) do
if v.lhs == v2.lhs and v.mode == v2.mode and v.rhs ~= v2.rhs then
duplicates[v.lhs] = { { v }, { v2 } }
duplicates[v.lhs] = { v, v2 }
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions tests/hawtkeys/utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe("utils functionality", function()
}
local duplicates = utils.find_duplicates(keymaps)
eq(2, #duplicates.a)
eq("a", duplicates.a[1][1].lhs)
eq("a", duplicates.a[2][1].lhs)
eq("a", duplicates.a[1].lhs)
eq("a", duplicates.a[2].lhs)
end)

it("can find multiple duplicate lhs in table", function()
Expand All @@ -26,10 +26,10 @@ describe("utils functionality", function()
}
local duplicates = utils.find_duplicates(keymaps)
eq(2, #duplicates.a)
eq("a", duplicates.a[1][1].lhs)
eq("a", duplicates.a[2][1].lhs)
eq("a", duplicates.a[1].lhs)
eq("a", duplicates.a[2].lhs)
eq(2, #duplicates.b)
eq("b", duplicates.b[1][1].lhs)
eq("b", duplicates.b[2][1].lhs)
eq("b", duplicates.b[1].lhs)
eq("b", duplicates.b[2].lhs)
end)
end)

0 comments on commit 683e163

Please sign in to comment.