lazy.nvim icon indicating copy to clipboard operation
lazy.nvim copied to clipboard

feat(health): Warn about unused keys when normalizing a LazySpec[]

Open pynappo opened this issue 1 year ago • 1 comments

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): image

This is how a longer warning looks like: image

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.

pynappo avatar Jan 28 '24 23:01 pynappo

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.

pynappo avatar Feb 08 '24 02:02 pynappo

This PR is stale because it has been open 60 days with no activity.

github-actions[bot] avatar Jul 06 '24 01:07 github-actions[bot]

Not a fan of this. Closing. ty

folke avatar Jul 07 '24 06:07 folke