fix: UNKNOWN PLUGIN error resulting from unloaded buffers #931
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.
Problem
Currently when checking if a buffer is valid, we use the function nvim_buf_is_valid, however there is an edge case here described in the documentation where a buffer could have been unloaded, but still be "valid". If a buffer is unloaded and valid then referencing
buf.buflisted
could result in a(UNKNOWN PLUGIN): Error executing lua: attempt to call a number value
error. I believe this issue may be a bug in Neovim itself and I have attempted to get more clarity on this here.This issue reproduced in my config when
bufferline
attempted to reference thebuf.buflisted
property of unloadednvim-tree
buffer.Note: A previous attempt at this fix (#928) attempted to address the issue by changing the call to
nvim_buf_is_valid
tonvim_buf_is_loaded
. While this solves the problem defined above, it had the side effect of breaking users of various session plugins. This is because session plugins utilize unloaded buffers which are also listed (i.e. calling.buflisted
on these buffers returns1
).Solution
Instead of utilizing
buf.buflisted
, which can potentially result inUNKNOWN PLUGIN
errors for certain unloaded buffers, we utilizevim.fn.getbufinfo
which returns a list of info tables for all buffers. This table contains a propertylisted
which is0
if the buffer is unlisted, and1
if the buffer is listed. This allows us to check whether the unloaded buffer is listed, without referencingbuf.buflisted
directly.I have locally verified that this solution both resolves the
UNKNOWN PLUGIN
errors, and supports loading "hidden" session buffers via the posession plugin.