Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(health): move health check to separate health file
- Loading branch information
Showing
3 changed files
with
55 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
local Keys = require("which-key.keys") | ||
|
||
local M = {} | ||
|
||
local start = vim.health.start or vim.health.report_start | ||
-- local ok = vim.health.ok or vim.health.report_ok | ||
local warn = vim.health.warn or vim.health.report_warn | ||
local error = vim.health.error or vim.health.report_error | ||
local info = vim.health.info or vim.health.report_info | ||
|
||
function M.check() | ||
start("WhichKey: checking conflicting keymaps") | ||
for _, tree in pairs(Keys.mappings) do | ||
Keys.update_keymaps(tree.mode, tree.buf) | ||
tree.tree:walk( | ||
---@param node Node | ||
function(node) | ||
local count = 0 | ||
for _ in pairs(node.children) do | ||
count = count + 1 | ||
end | ||
|
||
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 | ||
local msg = ("conflicting keymap exists for mode **%q**, lhs: **%q**"):format(tree.mode, node.mapping.prefix) | ||
warn(msg) | ||
local cmd = node.mapping.cmd or " " | ||
info(("rhs: `%s`"):format(cmd)) | ||
end | ||
end | ||
) | ||
end | ||
if next(Keys.duplicates) == nil then | ||
vim.fn["health#report_ok"]("No conflicting keymaps found") | ||
return | ||
end | ||
for _, dup in pairs(Keys.duplicates) do | ||
local msg = "" | ||
if dup.buf == dup.other.buffer then | ||
msg = "duplicate keymap" | ||
else | ||
msg = "buffer-local keymap overriding global" | ||
end | ||
msg = (msg .. " for mode **%q**, buf: %d, lhs: **%q**"):format(dup.mode, dup.buf or 0, dup.prefix) | ||
if dup.buf == dup.other.buffer then | ||
error(msg) | ||
else | ||
warn(msg) | ||
end | ||
info(("old rhs: `%s`"):format(dup.other.rhs or "")) | ||
info(("new rhs: `%s`"):format(dup.cmd or "")) | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters