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
4.75k stars 154 forks source link

bug: module 'which-key' not found (Lazy.nvim) after registering maps #560

Closed OWL4C closed 1 week ago

OWL4C commented 6 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.4 Build type: Release LuaJIT 2.1.1700008891

Operating system/version

MacOS 11.5

Describe the bug

Which Key works fine until i try to register anything, from anywhere. This will completely stop any plugins from loading and throw the error (full path abbreviated):

Error detected while processing init.lua:
Error while calling lua chunk lua/config/which-key.lua:1 module 'which-key' not found
(Listing all searched files)
stack traceback:
        [C]: in function 'require'
       lua/config/which-key.lua:1: in main chunk
        [C]: in function 'require'
        lua/config/init.lua:19: in main chunk
        [C]: in function 'require'
        init.lua:1: in main chunk

Steps To Reproduce

See under Repro

Expected Behavior

Not throw the error and break any plugins

Repro

Using lazy.nvim i have following relevant files (truncated for legibility)
lua/config/keymaps.lua: `require("config/which-key")`
lua/config/which-key.lua: `local wk = require("which-key")
-- As an example, we will create the following mappings:
--  * <leader>ff find files
--  * <leader>fr show recent files
--  * <leader>fb Foobar
-- we'll document:
--  * <leader>fn new file
--  * <leader>fe edit file
-- and hide <leader>1

wk.register({
  f = {
    name = "file", -- optional group name
    f = { "<cmd>Telescope find_files<cr>", "Find File" }, -- create a binding with label
    r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File", noremap=false, buffer = 123 }, -- additional options for creating the keymap
    n = { "New File" }, -- just a label. don't create any mapping
    e = "Edit File", -- same as above
    ["1"] = "which_key_ignore",  -- special label to hide it in the popup
    b = { function() print("bar") end, "Foobar" } -- you can also pass functions!
  },
}, { prefix = "<leader>" })` (the example from this git)
lua/plugins/which-key.lua: `local wk = require("which-key")
-- As an example, we will create the following mappings:
--  * <leader>ff find files
--  * <leader>fr show recent files
--  * <leader>fb Foobar
-- we'll document:
--  * <leader>fn new file
--  * <leader>fe edit file
-- and hide <leader>1

wk.register({
  f = {
    name = "file", -- optional group name
    f = { "<cmd>Telescope find_files<cr>", "Find File" }, -- create a binding with label
    r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File", noremap=false, buffer = 123 }, -- additional options for creating the keymap
    n = { "New File" }, -- just a label. don't create any mapping
    e = "Edit File", -- same as above
    ["1"] = "which_key_ignore",  -- special label to hide it in the popup
    b = { function() print("bar") end, "Foobar" } -- you can also pass functions!
  },
}, { prefix = "<leader>" })`
alexsmartens commented 1 week ago

Renaming which-key.nvim.lua to which-key.lua helped in my case