Repository navigation
fix: defer render when buffer numbers aren't assigned yet - #591
Closed
jonsmithers wants to merge 2 commits into
Closed
jonsmithers wants to merge 2 commits into
jonsmithers wants to merge 2 commits into
Conversation
vim.wait() drains scheduled callbacks, so re-queueing with vim.schedule from inside the wait that blocks bufnr assignment spun forever.
Author
|
jk this causes problems |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
:CodeDiffcan throw while switching files if something runs a blockingvim.wait()during the window switch insideopen_real_file():I hit this with nvim-tree open:
nvim_set_current_wintriggers aBufEnterautocmd for theNvimTree_*buffer, nvim-tree reloads its git state and callsvim.wait(), and that drains scheduled callbacks. One of them isrender_everything, which runs beforeopen_real_filehas returned.info.bufnrfor the real side is stillnil, sonvim_buf_is_valid(nil)throws.Fix
In
render_everything, if eitherbufnrisn't assigned yet, reschedule instead of continuing. By the next tickreload_sidehas returned and both buffers are set. Simply returning early would hide the error but never draw the diff, so I reschedule. The retry usesvim.defer_fnrather thanvim.schedule:vim.wait()drains scheduled callbacks, so re-queueing withvim.schedulefrom inside the wait spins forever (nvim hangs), whereas a timer fires after the wait returns.current()is still checked first, so a stale session stops retrying.render_everythingis now declared before assignment so it can reference itself.Related
nvim_buf_is_valid(nil)crash at this guard, triggered by LSP attach. It was closed by fix: prevent LSP attachment to virtual diff buffers (#140) #259, which removes that trigger but not the underlying race.open_real_fileto usenvim_win_call, which avoids thenvim_set_current_winthat starts the trace above. This PR is independent and guards the race itself.Testing
Verified headless:
:CodeDiff, then<CR>on a modified file in the explorer with nvim-tree'sBufEnterautocmd active, returns without error or hang. The original stack trace was reproduced separately. The full test suite has not been run and no regression test is included.🤖 Generated with Claude Code