fix: guard against external autocmd failures on buffer set#30
Merged
dlyongemallo merged 1 commit intomainfrom Mar 9, 2026
Merged
fix: guard against external autocmd failures on buffer set#30dlyongemallo merged 1 commit intomainfrom
dlyongemallo merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a safer wrapper around nvim_win_set_buf() to recover from failures caused by external autocommands, and integrates it into Diffview buffer/panel window setup to avoid hard failures during view open.
Changes:
- Introduce
utils.set_win_buf()to retrynvim_win_set_buf()once with window/buffer events ignored. - Replace direct
api.nvim_win_set_buf()calls withutils.set_win_buf()in key buffer-setting paths. - Add functional tests for
utils.set_win_buf()and add a one-time user warning + logging when recovery happens while opening a Diffview buffer.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lua/diffview/utils.lua | Adds set_win_buf() helper with a retry path using no_win_event_call(). |
| lua/diffview/scene/window.lua | Uses set_win_buf() for opening diff buffers; warns/logs when recovery occurs and falls back on failure. |
| lua/diffview/vcs/file.lua | Uses set_win_buf() when loading the null buffer into a window. |
| lua/diffview/ui/panel.lua | Uses set_win_buf() when opening the panel split and assigning its buffer. |
| lua/diffview/tests/functional/utils_spec.lua | Adds functional tests for set_win_buf() behavior across success/retry/failure cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d65d8c6 to
bc505bf
Compare
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.
Workaround for an error message originating from nvim-lualine/lualine.nvim#699.