Skip to content

fix: clean up diffpatch new buffer#261

Open
rvdeguzman wants to merge 1 commit into
nickjvandyke:mainfrom
rvdeguzman:fix/remove-new-buf-after-edit
Open

fix: clean up diffpatch new buffer#261
rvdeguzman wants to merge 1 commit into
nickjvandyke:mainfrom
rvdeguzman:fix/remove-new-buf-after-edit

Conversation

@rvdeguzman
Copy link
Copy Markdown

@rvdeguzman rvdeguzman commented May 13, 2026

Tasks

  • I read CONTRIBUTING.md
  • I reviewed AI-generated code myself
  • I addressed any automated check failures
  • I addressed AI review feedback (if any)

Description

When diffpatch is called, it creates a .new buffer and doesn't clean it up. This PR captures and removes the .new buffer when the diff tab is closed

Testing

  1. Ran a headless Neovim repro that simulates an edit permission diff with :diffpatch.

Related Issue(s)

Fixes #258

Screenshots/Videos

@rvdeguzman rvdeguzman marked this pull request as ready for review May 13, 2026 03:34
Copilot AI review requested due to automatic review settings May 13, 2026 03:34
@rvdeguzman
Copy link
Copy Markdown
Author

Hello first PR would like some feedback if anything needs changing, thank you

Copy link
Copy Markdown
Contributor

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

Fixes lingering :diffpatch.new” buffers created during edit permission diffs by tracking the generated buffer and deleting it when the diff UI is closed or when a permission reply closes the diff automatically.

Changes:

  • Track the .new buffer created by :diffpatch and mark it unlisted.
  • Delete the tracked .new buffer when closing the diff (q) and when handling permission.replied.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nickjvandyke
Copy link
Copy Markdown
Owner

Thank you for contributing! 😀

Sorry I didn't realize the opencode-review check was broken on PRs from forks. Gonna take this opportunity to troubleshoot that first if you don't mind 😅

@rvdeguzman
Copy link
Copy Markdown
Author

Thank you for contributing! 😀

Sorry I didn't realize the opencode-review check was broken on PRs from forks. Gonna take this opportunity to troubleshoot that first if you don't mind 😅

no prob!! thank you for taking your time and letting me know 🙇‍♂️🙇‍♂️

Copy link
Copy Markdown
Owner

@nickjvandyke nickjvandyke left a comment

Choose a reason for hiding this comment

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

Generally looks good, just a couple questions regarding simplification and reliability! Let me know if you have any questions 🙂

diff_tabpage = vim.api.nvim_get_current_tabpage()
diff_new_buf = vim.api.nvim_get_current_buf()

if vim.api.nvim_buf_get_name(diff_new_buf) == bufname .. ".new" then
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is the if necessary? I would think this will always succeed, but maybe I'm missing an edge case.

Nice thought to also make it unlisted!

Comment on lines +101 to +104
if diff_new_buf and vim.api.nvim_buf_is_valid(diff_new_buf) then
vim.api.nvim_buf_delete(diff_new_buf, { force = true })
end
diff_new_buf = nil
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I wonder if we could delete the buffer in an autocmd? Maybe on TabClosed (checking that it's diff_tabpage)? That would cover unforeseen cases, like the user manually closes both windows in the diff tab. There may be a better autocmd but that's what comes to mind atm.


local filepath = event.properties.metadata.filepath
-- Close any buffer with the same name, to avoid "Buffer with this name already exists" error when successive edit requests come in for the same file.
vim.cmd("silent! bwipeout " .. filepath .. ".new")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We might be able to remove this now? Presuming cleanup is reliable.

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.

bug: <file>.new buffer persists after edit request diff

3 participants