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.12k stars 163 forks source link

bug: Uses string instead of function in nested mappings doesn't work #790

Closed stounfo closed 1 month ago

stounfo commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0 Build type: Release LuaJIT 2.1.1720049189

Operating system/version

MacOS 14.3

Describe the bug

If I use a string as a second parameter to wk.Spec in a nested mapping (expand) the mapping doesn't work.

Steps To Reproduce

  1. nvim -u repro.lua
  2. type ?f

Expected Behavior

text "doesnt work" should be printed

Health

No response

Log

No response

Repro

vim.env.LAZY_STDPATH = ".repro"
load(
    vim.fn.system(
        "curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"
    )
)()

require("lazy.minit").repro({
    spec = {
        {
            "folke/which-key.nvim",
            opts = {
                spec = {
                    {
                        "?",
                        expand = function()
                            return {
                                { "f", "<cmd> echo 'doesnt work'<cr>" },  -- <- this mapping doesn't work
                                {
                                    "s",
                                    function()
                                        print("work")  -- <- this mapping works fine
                                    end,
                                },
                            }
                        end,
                    },
                },
            },
        },
    },
})
folke commented 1 month ago

Dynamic mappings only support functions (since they're not real mappings). I've updated the docs to reflect this.