Skip to content

fix: guard against external autocmd failures on buffer set#30

Merged
dlyongemallo merged 1 commit intomainfrom
guard_against_external_autocmd_failures
Mar 9, 2026
Merged

fix: guard against external autocmd failures on buffer set#30
dlyongemallo merged 1 commit intomainfrom
guard_against_external_autocmd_failures

Conversation

@dlyongemallo
Copy link
Copy Markdown
Owner

@dlyongemallo dlyongemallo commented Mar 5, 2026

Workaround for an error message originating from nvim-lualine/lualine.nvim#699.

Copilot AI review requested due to automatic review settings March 5, 2026 11:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 retry nvim_win_set_buf() once with window/buffer events ignored.
  • Replace direct api.nvim_win_set_buf() calls with utils.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.

Comment thread lua/diffview/utils.lua
Comment thread lua/diffview/tests/functional/utils_spec.lua Outdated
@dlyongemallo dlyongemallo force-pushed the guard_against_external_autocmd_failures branch from d65d8c6 to bc505bf Compare March 5, 2026 12:06
@dlyongemallo dlyongemallo merged commit 54afbf0 into main Mar 9, 2026
2 checks passed
@dlyongemallo dlyongemallo deleted the guard_against_external_autocmd_failures branch March 9, 2026 09:02
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.

2 participants