Repository navigation
Conversation
A scheduled render can run re-entrantly while M.update is still loading the other side: vim.wait inside an LspAttach handler (e.g. yaml-companion's request_sync) during open_real_file's :edit pumps the vim.schedule queue, so the other side's bufnr may still be nil when render_everything runs. nvim_buf_is_valid(nil) throws instead of returning false, and dropping the render would leave the view unrendered because readiness fires only once. Defer the render instead: remember the attempt and re-arm it once both sides are loaded. Adds a regression test reproducing the crash before the fix. Closes esmuellert#592
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.
Summary
Fixes the crash in #592: refreshing a YAML diff with yaml-companion installed could throw
update.lua:210: Invalid 'buf': Expected Lua number, and the view was then left unrendered.Root cause
When the virtual side's content arrives from the (warm) git cache,
render_when_reloadedqueuesrender_everythingwithvim.schedule. Avim.waitinside an LspAttach handler — yaml-companion'srequest_sync— during the real side's:editpumps that queue beforeopen_real_filehas returned, somodified_info.bufnris stillnilwhen the render runs.nvim_buf_is_valid(nil)throws instead of returningfalse, and simply returning would lose the render entirely because readiness fires only once.Changes
lua/codediff/ui/view/side_by_side/update.lua: if either side'sbufnris stillnilwhenrender_everythingruns, remember the attempt (render_deferred) instead of callingnvim_buf_is_validon it, and re-arm the render withvim.scheduleonceM.updatehas loaded both sides.tests/integration/ui/view/update_nil_bufnr_spec.lua: regression test. AFileTypeautocmd that callsvim.wait(50)stands in for yaml-companion'srequest_syncpump (no real LSP server needed).Evidence
Base SHA:
eee54e78e6f152a6eb03b090e95f7576c96a5ad9(main), Neovim 0.12.6.Before the fix — the new spec fails on
mainwith the exact error from the issue:After the fix — the spec passes, and the view renders the change:
Control case (in the same spec): an ordinary view created without the
vim.waitpump renders its diff normally, before and after the fix.Regression scope run:
styluawas not available in the environment where I ran the tests, somake lintwas not run locally; the added lines follow the surrounding 2-space style and are well under the configured line width.Scope and risks checked
when_allmechanism,reload_side,open_real_file, and the conflict-mode render path. The conflict-mode inner guard reads the same locals, but only after the outer guard has passed, and nothing writesnilinto them afterwards, so it cannot see anilbufnr.side_by_side/create.luaandinline_view/{create,update}.luaonly render after both buffers are assigned synchronously (or always hold real buffer numbers), so they cannot hitnvim_buf_is_valid(nil).current()(generation) first.vim.waitduring:edit) and the exact crash site instead.Closes #592