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: error on startup #754

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

On startup I get an error: clipboard: error: Error: target STRING not available 2024-07-18_08:11:59_screenshot

Steps To Reproduce

  1. nvim -u repro.lua
  2. See error

Expected Behavior

No error 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 ~
- WARNING |mini.icons| is not installed
- WARNING |nvim-web-devicons| is not installed
- WARNING Keymap icon support will be limited.

Checking for issues with your mappings ~
- OK No issues reported

checking for overlapping keymaps ~
- WARNING In mode `n`, <gc> overlaps with <gcc>:
  - <gc>: Toggle comment
  - <gcc>: Toggle comment line
- 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

Debug Started for v3.9.0
Plugin("marks").expand
Plugin("marks").expand
Plugin("registers").expand
new Mode(n:1)
Trigger(add) Mode(n:1) ` ' " g' g` z= g z ] [ <C-W>
on_key: :
ModeChanged(n:c)
  Plugin("registers").expand
  new Mode(c:1)
  Safe(true)
Trigger(add) Mode(c:1) <C-R>
on_key: q
on_key: <CR>
ModeChanged(c:n)
  Unsafe(command-mode)
  suspend: Mode(n:1)
  Trigger(del) Mode(n:1) " g' g` z= g z ] [ ` <C-W> '
Trigger(add) Mode(n:1) ` ' " g' g` z= g z ] [ <C-W>

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 = {} },
    -- add any other plugins here
  },
})
folke commented 1 month ago

I don't get that error. What does :checkhealth vim.provider show?

mehalter commented 1 month ago
provider.clipboard: require("provider.clipboard.health").check()

Clipboard (optional) ~
- OK Clipboard tool found: xclip

Here is a recording of the occurrences: https://asciinema.org/a/9rJ5caRiafJol3wwDXV9IKxKm

In this recording each time it happened. It seems like every once in a while it will not display it, then go on a few restarts with it not happening, then kick back up again

folke commented 1 month ago

Fixed in two ways:

mehalter commented 1 month ago

ah I see I'm a moment too slow! Thanks so much for taking a look! Based on the code you just pushed it seems like that's probably the problem. A race condition of some kind which would be the reason it was not happening every single time in my experience.

Thank you again for your ongoing support!

folke commented 1 month ago

I just checked the Neovim source code and unfortunately that warning can't be prevented. It happens when the clipboard tool doesn't return a value for the register. On wayland, this is the case after restart when the clipboard is still empty.

mehalter commented 1 month ago

Interesting, there must be something similar with Xorg as well since I'm not using Wayland. Thanks for the insight and taking a look!

folke commented 1 month ago

But https://github.com/folke/which-key.nvim/commit/27e47163165fee8e45b43d340db9335001403d2f should at least prevent showing that warning at startup. It may still be shown when you do " with an empty clipboard.

folke commented 1 month ago

https://github.com/neovim/neovim/blob/master/runtime/autoload/provider/clipboard.vim#L43