folke / which-key.nvim

💥 Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type.
Apache License 2.0
5.43k stars 177 forks source link

bug: Startup Error Message #820

Closed garcialn closed 3 months ago

garcialn commented 3 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

Pop!_OS 22.04-LTS

Describe the bug

Since the new release, every time i open nvim, i get an error message linked to which-key, when i proceed with :checkhealth which-key i noticed that the ERRORS are related to "" keymaps (but only those added with require("which-key").add{}) or WARNINGS to keymaps that have similar bindings, but not repeated (overlapping). My problem is actually about the startup message (which i believe is only connected to the <leader> keymaps errors), not really about the :checkhealth output...

Steps To Reproduce

  1. Add keymaps that use the <leader> binding
  2. Set keymaps that have similar bindings (but not the same)
  3. :checkhealth which-key

Expected Behavior

No errors with <leader> binding, which would lead to no error message on startup...

Health

==============================================================================
which-key: require("which-key.health").check()

- OK Most of these checks are for informational purposes only.
  WARNINGS should be treated as a warning, and don't necessarily indicate a problem with your config.
  Please |DON't| report these warnings as an issue.

Checking your config ~
- OK |mini.icons| is installed
- OK |nvim-web-devicons| is installed

Checking for issues with your mappings ~
- ERROR Invalid field `<leader>c`: >
  {
    ["<leader>c"] = {
      _ = "which_key_ignore",
      name = "[C]ode"
    },
    ["<leader>d"] = {
      _ = "which_key_ignore",
      name = "[D]ocument"
    },
    ["<leader>h"] = {
      _ = "which_key_ignore",
      name = "Git [H]unk"
    },
    ["<leader>r"] = {
      _ = "which_key_ignore",
      name = "[R]ename"
    },
    ["<leader>s"] = {
      _ = "which_key_ignore",
      name = "[S]earch"
    },
    ["<leader>t"] = {
      _ = "which_key_ignore",
      name = "[T]oggle"
    },
    ["<leader>w"] = {
      _ = "which_key_ignore",
      name = "[W]orkspace"
    }
  }
- ERROR Invalid field `<leader>d`: >
  {
    ["<leader>c"] = {
      _ = "which_key_ignore",
      name = "[C]ode"
    },
    ["<leader>d"] = {
      _ = "which_key_ignore",
      name = "[D]ocument"
    },
    ["<leader>h"] = {
      _ = "which_key_ignore",
      name = "Git [H]unk"
    },
    ["<leader>r"] = {
      _ = "which_key_ignore",
      name = "[R]ename"
    },
    ["<leader>s"] = {
      _ = "which_key_ignore",
      name = "[S]earch"
    },
    ["<leader>t"] = {
      _ = "which_key_ignore",
      name = "[T]oggle"
    },
    ["<leader>w"] = {
      _ = "which_key_ignore",
      name = "[W]orkspace"
    }
  }
- ERROR Invalid field `<leader>h`: >
  {
    ["<leader>c"] = {
      _ = "which_key_ignore",
      name = "[C]ode"
    },
    ["<leader>d"] = {
      _ = "which_key_ignore",
      name = "[D]ocument"
    },
    ["<leader>h"] = {
      _ = "which_key_ignore",
      name = "Git [H]unk"
    },
    ["<leader>r"] = {
      _ = "which_key_ignore",
      name = "[R]ename"
    },
    ["<leader>s"] = {
      _ = "which_key_ignore",
      name = "[S]earch"
    },
    ["<leader>t"] = {
      _ = "which_key_ignore",
      name = "[T]oggle"
    },
    ["<leader>w"] = {
      _ = "which_key_ignore",
      name = "[W]orkspace"
    }
  }
- ERROR Invalid field `<leader>r`: >
  {
    ["<leader>c"] = {
      _ = "which_key_ignore",
      name = "[C]ode"
    },
    ["<leader>d"] = {
      _ = "which_key_ignore",
      name = "[D]ocument"
    },
    ["<leader>h"] = {
      _ = "which_key_ignore",
      name = "Git [H]unk"
    },
    ["<leader>r"] = {
      _ = "which_key_ignore",
      name = "[R]ename"
    },
    ["<leader>s"] = {
      _ = "which_key_ignore",
      name = "[S]earch"
    },
    ["<leader>t"] = {
      _ = "which_key_ignore",
      name = "[T]oggle"
    },
    ["<leader>w"] = {
      _ = "which_key_ignore",
      name = "[W]orkspace"
    }
  }
- ERROR Invalid field `<leader>s`: >
  {
    ["<leader>c"] = {
      _ = "which_key_ignore",
      name = "[C]ode"
    },
    ["<leader>d"] = {
      _ = "which_key_ignore",
      name = "[D]ocument"
    },
    ["<leader>h"] = {
      _ = "which_key_ignore",
      name = "Git [H]unk"
    },
    ["<leader>r"] = {
      _ = "which_key_ignore",
      name = "[R]ename"
    },
    ["<leader>s"] = {
      _ = "which_key_ignore",
      name = "[S]earch"
    },
    ["<leader>t"] = {
      _ = "which_key_ignore",
      name = "[T]oggle"
    },
    ["<leader>w"] = {
      _ = "which_key_ignore",
      name = "[W]orkspace"
    }
  }
- ERROR Invalid field `<leader>t`: >
  {
    ["<leader>c"] = {
      _ = "which_key_ignore",
      name = "[C]ode"
    },
    ["<leader>d"] = {
      _ = "which_key_ignore",
      name = "[D]ocument"
    },
    ["<leader>h"] = {
      _ = "which_key_ignore",
      name = "Git [H]unk"
    },
    ["<leader>r"] = {
      _ = "which_key_ignore",
      name = "[R]ename"
    },
    ["<leader>s"] = {
      _ = "which_key_ignore",
      name = "[S]earch"
    },
    ["<leader>t"] = {
      _ = "which_key_ignore",
      name = "[T]oggle"
    },
    ["<leader>w"] = {
      _ = "which_key_ignore",
      name = "[W]orkspace"
    }
  }
- ERROR Invalid field `<leader>w`: >
  {
    ["<leader>c"] = {
      _ = "which_key_ignore",
      name = "[C]ode"
    },
    ["<leader>d"] = {
      _ = "which_key_ignore",
      name = "[D]ocument"
    },
    ["<leader>h"] = {
      _ = "which_key_ignore",
      name = "Git [H]unk"
    },
    ["<leader>r"] = {
      _ = "which_key_ignore",
      name = "[R]ename"
    },
    ["<leader>s"] = {
      _ = "which_key_ignore",
      name = "[S]earch"
    },
    ["<leader>t"] = {
      _ = "which_key_ignore",
      name = "[T]oggle"
    },
    ["<leader>w"] = {
      _ = "which_key_ignore",
      name = "[W]orkspace"
    }
  }
- ERROR Invalid field `<leader>h`: >
  {
    ["<leader>h"] = { "Git [H]unk" }
  }

checking for overlapping keymaps ~
- WARNING In mode `n`, <1> overlaps with <10>:

- WARNING In mode `n`, <sr> overlaps with <srl>, <srn>:
  - <sr>: Replace surrounding
  - <srl>: Replace previous surrounding
  - <srn>: Replace next surrounding
- WARNING In mode `n`, <sd> overlaps with <sdl>, <sdn>:
  - <sd>: Delete surrounding
  - <sdl>: Delete previous surrounding
  - <sdn>: Delete next surrounding
- WARNING In mode `n`, <sh> overlaps with <shl>, <shn>:
  - <sh>: Highlight surrounding
  - <shl>: Highlight previous surrounding
  - <shn>: Highlight next surrounding
- WARNING In mode `n`, <sF> overlaps with <sFl>, <sFn>:
  - <sF>: Find left surrounding
  - <sFl>: Find previous left surrounding
  - <sFn>: Find next left surrounding
- WARNING In mode `n`, <sf> overlaps with <sfl>, <sfn>:
  - <sf>: Find right surrounding
  - <sfl>: Find previous right surrounding
  - <sfn>: Find next right surrounding
- WARNING In mode `n`, <gc> overlaps with <gcO>, <gco>, <gcc>, <gcA>:
  - <gc>: Comment toggle linewise
  - <gcO>: Comment insert above
  - <gco>: Comment insert below
  - <gcc>: Comment toggle current line
  - <gcA>: Comment insert end of line
- WARNING In mode `n`, <gs> overlaps with <gss>:
  - <gs>: Sort operator
  - <gss>: Sort line
- WARNING In mode `n`, <gx> overlaps with <gxx>:
  - <gx>: Exchange operator
  - <gxx>: Exchange line
- WARNING In mode `n`, <gr> overlaps with <grr>:
  - <gr>: Replace operator
  - <grr>: Replace line
- WARNING In mode `n`, <gb> overlaps with <gbc>:
  - <gb>: Comment toggle blockwise
  - <gbc>: Comment toggle current block
- WARNING In mode `n`, <g=> overlaps with <g==>:
  - <g=>: Evaluate operator
  - <g==>: Evaluate line
- WARNING In mode `n`, <gm> overlaps with <gmm>:
  - <gm>: Multiply operator
  - <gmm>: Multiply line
- WARNING In mode `x`, <a> overlaps with <ai>, <an>, <a%>, <al>:
  - <a>: Around textobject
  - <ai>: Object scope with border
  - <an>: Around next textobject
  - <al>: Around last textobject
- WARNING In mode `x`, <i> overlaps with <ii>, <in>, <il>:
  - <i>: Inside textobject
  - <ii>: Object scope
  - <in>: Inside next textobject
  - <il>: Inside last textobject
- WARNING In mode `o`, <a> overlaps with <ai>, <an>, <al>:
  - <a>: Around textobject
  - <ai>: Object scope with border
  - <an>: Around next textobject
  - <al>: Around last textobject
- WARNING In mode `o`, <i> overlaps with <ii>, <in>, <il>:
  - <i>: Inside textobject
  - <ii>: Object scope
  - <in>: Inside next textobject
  - <il>: Inside last textobject
- OK Overlapping keymaps are only reported for informational purposes.
  This doesn't necessarily mean there is a problem with your config.

Checking for duplicate mappings ~
- OK No duplicate mappings found

Log

# Error message

There were issues reported with your **which-key** mappings.
Use `:checkhealth which-key` to find out more.

Repro

# Wk config

{ -- Useful plugin to show you pending keybinds.
    'folke/which-key.nvim',
    event = 'VimEnter', -- Sets the loading event to 'VimEnter'
    config = function() -- This is the func that runs, AFTER loading
      require('which-key').setup()

      -- Document existing key chains
      require('which-key').add {
        ['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
        ['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
        ['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
        ['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
        ['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
        ['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' },
        ['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
      }
      -- visual mode
      require('which-key').add({
        ['<leader>h'] = { 'Git [H]unk' },
      }, { mode = 'v' })
    end,
  },
max397574 commented 3 months ago

your setup is wrong look at the readme the "<leader>c" should be inside the table also idk what you intend to do with the _ =" which_key_ignore" there is no such field

garcialn commented 3 months ago

Indeed, you were correct... I was using the standard which-key config from kickstart.nvim, and since it was working before, i didn't even think to look into it. Today i refactored it according to which-key docs and everything is working fine. Thank you for the heads up 😉