lazy.nvim
lazy.nvim copied to clipboard
feat(health): Warn about unused keys when normalizing a LazySpec[]
Occasionally, users may put the configuration keys for a plugin into a LazySpec[], rather than a specific LazySpec. Alternatively, they may add a new LazySpec|string into an existing LazySpec for a plugin. This leads to some configuration keys being silently ignored by lazy.nvim after normalization, which can be confusing to new lazy.nvim users.
This PR adds a health check to Spec:normalize() which will warn about the misplaced keys.
Example of a LazySpec[] that will trigger this:
return {
{
'lewis6991/gitsigns.nvim',
event = { 'BufNewFile', 'BufReadPre' },
dependencies = { 'nvim-lua/plenary.nvim' },
opts = {
signs = {
add = { hl = 'GitSignsAdd', text = '│', numhl = 'GitSignsAddNr', linehl = 'GitSignsAddLn' },
change = { hl = 'GitSignsChange', text = '│', numhl = 'GitSignsChangeNr', linehl = 'GitSignsChangeLn' },
delete = { hl = 'GitSignsDelete', text = '_', numhl = 'GitSignsDeleteNr', linehl = 'GitSignsDeleteLn' },
topdelete = { hl = 'GitSignsDelete', text = '‾', numhl = 'GitSignsDeleteNr', linehl = 'GitSignsDeleteLn' },
changedelete = { hl = 'GitSignsChange', text = '~', numhl = 'GitSignsChangeNr', linehl = 'GitSignsChangeLn' },
},
numhl = true, -- Toggle with `:Gitsigns toggle_numhl`
watch_gitdir = {
interval = 1000,
follow_files = true,
},
},
'pwntester/octo.nvim',
},
}
The resulting healthcheck warning with this PR (:Lazy health):
This is how a longer warning looks like:
Concerns:
- On my machine, this PR can slow down spec processsing by a few ms when warning about big tables (I assume due to
vim.inspect). For reference, spec processing takes ~5ms for me without this warning. - How should I word and format the warning message? The current method is admittedly hacky, but I like how it looks.
Added an extra check for normalization, see the f453010 (#1299) description. It happens to fit under the intention of this PR so I added it here (without the extra check, lazy.nvim could error with a vague stacktrace, with this PR it's now a healthcheck warning), but I could split it into a seperate fix(plugin): PR if you would like.
This PR is stale because it has been open 60 days with no activity.
Not a fan of this. Closing. ty