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: Breaks built in mappings #609

Closed mehalter closed 1 month ago

mehalter commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0 (github release)

Operating system/version

Arch Linux

Describe the bug

It looks like something changed in the processing of mappings in the v2 release that breaks built in mappings such as << to de-indent.

E5108: Error executing lua ...bug/.repro/plugins/which-key.nvim/lua/which-key/util.lua:44: Invalid 'str': Expected Lua string     
stack traceback:                                                                                                                  
        [C]: in function 'nvim_replace_termcodes'                                                                                 
        ...bug/.repro/plugins/which-key.nvim/lua/which-key/util.lua:44: in function 't'                                           
        ...bug/.repro/plugins/which-key.nvim/lua/which-key/keys.lua:136: in function 'get_mappings'                               
        ...bug/.repro/plugins/which-key.nvim/lua/which-key/view.lua:278: in function 'on_keys'                                    
        ...bug/.repro/plugins/which-key.nvim/lua/which-key/view.lua:246: in function 'open'                                       
        ...bug/.repro/plugins/which-key.nvim/lua/which-key/init.lua:44: in function 'show'                                        
        [string ":lua"]:1: in main chunk

Steps To Reproduce

  1. nvim -u repro.lua , use the minimal reproducing config below
  2. <<, binding for decreasing indentation
  3. See error.

Expected Behavior

No error and all default mappings should still work.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "folke/which-key.nvim", config = true },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
folke commented 1 month ago

Can't reproduce with the repro. Are you 100% you're on the latest version?

mehalter commented 1 month ago

Please try again, the minimal repro.lua above reproduces the bug perfectly. Here is a recording showing me doing a fresh installation given the code above and walking through:

https://asciinema.org/a/eDq77UjzMbI7GCzwSs8TnraHT

mehalter commented 1 month ago
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info

Here are the full version details of the neovim version I am using

mehalter commented 1 month ago
NVIM v0.11.0-dev-189+g78d3f4742
Build type: RelWithDebInfo
LuaJIT 2.1.1716656478
Run "nvim -V1 -v" for more info

I have verified that I can also reproduce with the latest nightly

folke commented 1 month ago

I you run that repro, make sure to update the plugins in the repro as well

folke commented 1 month ago

nm, you deleted the files

mehalter commented 1 month ago

2024-06-06_10:44:43_screenshot

I have verified that I am on the latest.

folke commented 1 month ago

so weird, it all works fine for me

folke commented 1 month ago

https://github.com/folke/which-key.nvim/assets/292349/0cae648d-ea02-4728-9cc0-85c2d23a1e40

folke commented 1 month ago

ok, can reproduce now. First >> then << triggers the error

mehalter commented 1 month ago

Do the other way...

mehalter commented 1 month ago

I also agree that >> works as shown in my recording

folke commented 1 month ago

bisected it to https://github.com/folke/which-key.nvim/pull/600

Will check or revert

folke commented 1 month ago

reverted for now. had a quick look at that code and it's wrong for sure. will implement it myself

mehalter commented 1 month ago

Thanks! Definitely strange you have to indent first, on my end if I just do the exact steps I put in the issue and run << even as the first thing in the editor I get the problem

folke commented 1 month ago

I reverted the PR and just did a proper fix for those nested operators.

folke commented 1 month ago

Thank you for reporting!