fix: clean up diffpatch new buffer#261
Conversation
|
Hello first PR would like some feedback if anything needs changing, thank you |
There was a problem hiding this comment.
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
.newbuffer created by:diffpatchand mark it unlisted. - Delete the tracked
.newbuffer when closing the diff (q) and when handlingpermission.replied.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thank you for contributing! 😀 Sorry I didn't realize the |
no prob!! thank you for taking your time and letting me know 🙇♂️🙇♂️ |
eeca75c to
1f8be40
Compare
nickjvandyke
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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!
| 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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
We might be able to remove this now? Presuming cleanup is reliable.
Tasks
Description
When
diffpatchis called, it creates a.newbuffer and doesn't clean it up. This PR captures and removes the.newbuffer when the diff tab is closedTesting
:diffpatch.Related Issue(s)
Fixes #258
Screenshots/Videos