Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't reference unloaded buffers #928

Merged

Conversation

prettymuchbryce
Copy link
Contributor

@prettymuchbryce prettymuchbryce commented Jun 19, 2024

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 buflisted will result in a (UNKNOWN PLUGIN): Error executing lua: attempt to call a number value error.

Solution

Instead of nvim_buf_is_valid we use nvim_buf_is_loaded which checks both whether a buffer is valid and loaded. This way we never attempt to reference buflisted of unloaded or invalid buffers.

This PR should at least partially address #869. Applying the patch removes these errors for my config when invoking Neovim via nvim .. Because this error is so generic, it's possible that there could be more than one cause.

Copy link
Owner

@akinsho akinsho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, happy to give this a shot

@akinsho akinsho merged commit 6ac7e4f into akinsho:main Jun 23, 2024
@stevenxxiu
Copy link

stevenxxiu commented Jun 23, 2024

I just updated my plugins, and this commit causes bufferline to stop working with possession. With this commit, only the last used tab gets loaded.

@latipun7
Copy link

latipun7 commented Jun 23, 2024

I just updated my plugins, and this commit causes bufferline to stop working with possession. With this commit, only the last used tab gets loaded.

I use different session plugin and have same issue.
I guess all sessions are loaded, but only the last used buffer is showing on bufferline. I can't switch it with :BufferLineCyclePrev or :BufferLineCycleNext. I can switch to 2nd last buffer with :e #, and then bufferline shows two buffer.

@akinsho
Copy link
Owner

akinsho commented Jun 23, 2024

Sigh 😔 well worth a shot will revert for now, too many obscure requirements to get this working

akinsho added a commit that referenced this pull request Jun 23, 2024
akinsho added a commit that referenced this pull request Jun 23, 2024
* Revert "fix: UNKNOWN PLUGIN error resulting from unloaded buffers (#928)"

This reverts commit 6ac7e4f.

* refactor: check exists before listed
@prettymuchbryce
Copy link
Contributor Author

Sigh 😔 well worth a shot will revert for now, too many obscure requirements to get this working

Rolling back is the right call for now. Clearly this PR causes some unexpected side effects for session plugin users. I am happy to install possession and see if I can further root cause the issue. My initial hunch is that these plugins must intentionally utilize unloaded buffers in a way that I didn't initially anticipate.

@akinsho
Copy link
Owner

akinsho commented Jun 24, 2024

Someone suggested swapping the order of the exists check as a potential solution which I did. @prettymuchbryce can you see if that made a difference for you?

@prettymuchbryce
Copy link
Contributor Author

Someone suggested swapping the order of the exists check as a potential solution which I did. @prettymuchbryce can you see if that made a difference for you?

Unfortunately that solution does not resolve the UNKNOWN PLUGIN errors because that solution still attempts to call .buflisted on an unloaded buffer.

I have opened a new PR which I believe contains a working solution. That is— it resolves the UNKNOWN PLUGIN errors, while also maintaining support for session plugins that utilize hidden buffers. Let me know your thoughts.

#931

sstallion pushed a commit to sstallion/bufferline.nvim that referenced this pull request Jul 3, 2024
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 buflisted will result in a (UNKNOWN PLUGIN): Error executing lua: attempt to call a number value error.

Solution:
Instead of nvim_buf_is_valid we use nvim_buf_is_loaded which checks both whether a buffer is valid and loaded. This way we never attempt to reference buflisted of unloaded or invalid buffers.

This PR should at least partially address akinsho#869. Applying the patch removes these errors for my config when invoking Neovim via nvim .. Because this error is so generic, it's possible that there could be more than one cause.
sstallion pushed a commit to sstallion/bufferline.nvim that referenced this pull request Jul 3, 2024
* Revert "fix: UNKNOWN PLUGIN error resulting from unloaded buffers (akinsho#928)"

This reverts commit 6ac7e4f.

* refactor: check exists before listed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants