Fix: file/buffer-type disable does not prevent errors being thrown from keys.update function #578
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
in lua/which-key/init.lua show function:
The show function calls update before checking if which-key is enabled for that buffer type.
the update function can throw an error like the following, for example, in an oil.nvim buffer.
because disable option is not checked before calling it, even disabling which-key for that buffer or file type will not prevent these errors, making it impossible to use any keybinding that would have triggered the popup if it were enabled.
This means, to use oil, I would have to uninstall which-key
I added 1 check to prevent it from executing on disabled buffer and file types.
I thought it best to add the check to the update function itself rather than init's show function, in case it can get called from anywhere else in a disabled buffer.
The error I was getting on any keypress tracked by which-key within oil buffers despite it being disabled for oil filetype:
Note: I did not press g. I pressed space (my leader key) within an oil buffer in this particular error.