feat(#3037): add API node.buffer.delete, node.buffer.wipe#3040
feat(#3037): add API node.buffer.delete, node.buffer.wipe#3040alex-courtis merged 16 commits intonvim-tree:masterfrom
Conversation
There was a problem hiding this comment.
This works nicely, I look forward to using it.
- Revert
ApiTreeToggleOptschange - Change warning level of no-loaded-buffer
- Remove unused options
delete_bufferandwipe_buffer - Refactor action methods, message to follow
- Add help at 6.3 API NODE nvim-tree-api.node
lua/nvim-tree/api.lua
Outdated
| Api.tree.focus = Api.tree.open | ||
|
|
||
| ---@class ApiTreeToggleOpts | ||
| ---@class ApiTreeToggleOptsApiTreeTo |
There was a problem hiding this comment.
What's the reason for this change? lua/nvim-tree/actions/tree/toggle.lua is still using this class...
There was a problem hiding this comment.
No idea 😅 , this was probably done accidentally. Just reverted it 👍🏼
| Api.node.navigate.opened.prev = wrap_node(actions.moves.item.fn({ where = "prev", what = "opened" })) | ||
|
|
||
| ---@class ApiNodeDeleteWipeBufferOpts | ||
| ---@field force boolean|nil default false |
lua/nvim-tree.lua
Outdated
| close_window = true, | ||
| }, | ||
| delete_buffer = {}, | ||
| wipe_buffer = {}, |
There was a problem hiding this comment.
No, I was unsure if it was a convention to have these even if there are no underlying options, so I added these in even though they are empty.
I can remove them 👍🏼
There was a problem hiding this comment.
Tested permutations and combination with :ls! reporting as expected.
vim.keymap.set("n", "BW", function()
api.node.buffer.wipe(api.tree.get_node_under_cursor(), { force = false })
end, opts("Wipe"))
vim.keymap.set("n", "BD", function()
api.node.buffer.wipe(api.tree.get_node_under_cursor(), { force = true })
end, opts("Delete"))There was a problem hiding this comment.
Great! Thank you 👍🏼
lua/nvim-tree/actions/node/utils.lua
Outdated
| -- check if buffer for file at cursor exists and if it is loaded | ||
| local bufnr_at_filename = vim.fn.bufnr(filename) | ||
| if bufnr_at_filename == -1 or vim.fn.getbufinfo(bufnr_at_filename)[1].loaded == 0 then | ||
| notify.error("No loaded buffer coincides with " .. notify_node) |
There was a problem hiding this comment.
Can we please change this to INFO? Users may wish to ignore this message.
There was a problem hiding this comment.
Yeah, sure! Should I also change the error statement at line 37 (the one that says "Buffer for file " .. notify_node .. " is modified"), or just this one?
There was a problem hiding this comment.
I think just this one. Deleting a modified buffer truly is an error.
|
I like the modularity, it's really easy to read. Having 3 new files is not necessary, delete and wipe can be handled in one place: These actions do act on a node, and belong in
|
Ok, when I get some free time I'll work on these changes. Thanks for the review :) |
|
@alex-courtis I've pushed some commits, and I believe I have addressed all of your issues :) Kindly check when you can 🙏🏼 , thanks! |
|
Looks like we have some newly deprecated nvim methods : https://github.com/nvim-tree/nvim-tree.lua/actions/runs/12939265657/job/36091177064?pr=3040 I'll resolve them on master and merge. |
alex-courtis
left a comment
There was a problem hiding this comment.
In the interests of speed, I pushed fixes for the review comments.
Please let me know if you'd prefer me not to push.
lua/nvim-tree/actions/node/utils.lua
Outdated
There was a problem hiding this comment.
Looks like this file can go - everything is in buffer.lua
There was a problem hiding this comment.
Oh yeah, we can remove this, I forgot to do so, sorry!
| end | ||
|
|
||
| function M.setup(_) | ||
| end |
There was a problem hiding this comment.
We can remove this NOP; we're moving away from this setup pattern anyway.
| ---@param opts ApiNodeDeleteWipeBufferOpts|nil | ||
| ---@return nil | ||
| function M.delete(node, opts) | ||
| M.delete_buffer("delete", node.absolute_path, opts) |
There was a problem hiding this comment.
This handles nil or partial node gracefully, however not a malformed node like { aaaabsolute_path = "foo" }
That's OK - garbage in, garbage out.
@alex-courtis all good for me 🫡 ! Thanks for jumping in and resolving these 🙏🏼 |
alex-courtis
left a comment
There was a problem hiding this comment.
Many thanks for the fantastic addition
Thanks for that, and for assisting here! Would love to contribute again if there are any good opportunities for newcomers |
It's a pleasure to work with you and it'd be great to have another team member on board. There's a PR Please label on many features / bugs - issues that we just don't have the bandwidth for. Alternatively, there's a larger project for Multiple Instances under way. This task on the Project Board would be a good start - it's got a clear goal and definition of done. |
|
Added you as a project member so that you can push branches, review PRs, take tasks etc. |
Thank you! Likewise, it was a pleasure to contribute :)
Oh, nice! I think I'll pick up a bug so I get a bit more familiar with the project and Lua, as I'm not too familiar with the language and writing good code on it. |
Oh and of course, thanks for this! This is much appreciated :) |
This PR adds two API methods for respectively deleting and wiping the buffer for the current file under the tree cursor:
Api.node.buffer.delete; andApi.node.buffer.wipe,fixes #3037.
They both use the same underlying function defined in the new file added at
lua/actions/node/utils.lua.This function checks if there's an opened and loaded buffer for the file under the tree cursor.
If there isn't, it notifies an error message.
Otherwise, it deletes/wipes the buffer if it's not modified (unless
opts.forceistrue)I'm setting this as WIP because I haven't run the make commands yet.EDIT: done