Skip to content

Commit

Permalink
fix(health): dont show duplicates between global and buffer-local. It…
Browse files Browse the repository at this point in the history
…'s too confusing
  • Loading branch information
folke committed May 10, 2023
1 parent 912ef1a commit 015fdf3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lua/which-key/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local info = vim.health.info or vim.health.report_info

function M.check()
start("WhichKey: checking conflicting keymaps")
local conflicts = 0
for _, tree in pairs(Keys.mappings) do
Keys.update_keymaps(tree.mode, tree.buf)
tree.tree:walk(
Expand All @@ -22,6 +23,7 @@ function M.check()

local auto_prefix = not node.mapping or (node.mapping.group == true and not node.mapping.cmd)
if node.prefix_i ~= "" and count > 0 and not auto_prefix then
conflicts = conflicts + 1
local msg = ("conflicting keymap exists for mode **%q**, lhs: **%q**"):format(tree.mode, node.mapping.prefix)
warn(msg)
local cmd = node.mapping.cmd or " "
Expand All @@ -30,11 +32,11 @@ function M.check()
end
)
end
if next(Keys.duplicates) == nil then
if conflicts == 0 then
ok("No conflicting keymaps found")
return
end
for _, dup in pairs(Keys.duplicates) do
for _, dup in ipairs(Keys.duplicates) do
local msg = ""
if dup.buf == dup.other.buffer then
msg = "duplicate keymap"
Expand Down
2 changes: 1 addition & 1 deletion lua/which-key/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function M.map(mode, prefix_n, cmd, buf, opts)
---@diagnostic disable-next-line: undefined-field
return (ret and ret.lhs and ret.rhs and ret.rhs ~= cmd) and ret or nil
end)
if other then
if other and other.buffer == buf then
table.insert(M.duplicates, { mode = mode, prefix = prefix_n, cmd = cmd, buf = buf, other = other })
end
if buf ~= nil then
Expand Down

0 comments on commit 015fdf3

Please sign in to comment.