Skip to content

Commit

Permalink
fix(health): move deprecated option check to health
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 15, 2024
1 parent d9c7b9b commit af7a30f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
47 changes: 22 additions & 25 deletions lua/which-key/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ M.mappings = {}
---@type wk.Opts
M.options = nil

function M.deprecated()
return vim.tbl_filter(function(k)
return M.options[k] ~= nil
end, {
"operators",
"key_labels",
"motions",
"popup_mappings",
"window",
"ignore_missing",
"hidden",
"triggers_nowait",
"triggers_blacklist",
})
end

---@param opts? wk.Opts
function M.setup(opts)
if vim.fn.has("nvim-0.9") == 0 then
Expand All @@ -210,32 +226,13 @@ function M.setup(opts)
M.options = vim.tbl_deep_extend("force", {}, defaults, Presets[M.options.preset] or {}, opts or {})
end

local used_old = vim.tbl_filter(function(k)
return M.options[k] ~= nil
end, {
"operators",
"key_labels",
"motions",
"popup_mappings",
"window",
"ignore_missing",
"hidden",
"triggers_nowait",
"triggers_blacklist",
})
if #used_old > 0 then
local msg = {
"Your config uses deprecated options:",
}
vim.list_extend(
msg,
vim.tbl_map(function(o)
return "- `" .. o .. "`"
end, used_old)
)
msg[#msg + 1] = "\nPlease refer to the docs for the new options."
Util.warn(msg)
if #M.deprecated() > 0 then
Util.warn({
"Your config uses deprecated options.",
"Use `:checkhealth which-key` to find out more.",
}, { once = true })
end

local wk = require("which-key")

-- replace by the real add function
Expand Down
18 changes: 18 additions & 0 deletions lua/which-key/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ function M.check()
.. "WARNINGS should be treated as a warning, and don't necessarily indicate a problem with your config.\n"
.. "Please |DON't| report these warnings as an issue."
)

start("Checking your config")

local deprecated = Config.deprecated()
if #deprecated > 0 then
local msg = {
"Your config uses deprecated options:",
}
vim.list_extend(
msg,
vim.tbl_map(function(o)
return "- `" .. o .. "`"
end, deprecated)
)
msg[#msg + 1] = "Please refer to the docs for more info."
warn(table.concat(msg, "\n"))
end

local have_icons = false
for _, provider in ipairs(Icons.providers) do
if provider.available == nil then
Expand Down

0 comments on commit af7a30f

Please sign in to comment.