Skip to content

Commit

Permalink
Properly cleanup windows, buffers, and tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit committed Feb 4, 2024
1 parent 7ad7906 commit a53951a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lua/winmove/util/vader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,28 @@ function vader.given(...)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, contents)
end

local ok, err

-- TODO: Add custom formatter here?
vim.api.nvim_buf_call(bufnr, function()
callback({ bufnr = bufnr, win_id = vim.api.nvim_get_current_win() })
ok, err = pcall(callback, { bufnr = bufnr, win_id = vim.api.nvim_get_current_win() })
end)

-- Clean up all open buffers to ensure test isolation
-- Clean up all tabs, windows, and buffers to ensure test isolation
for _, win_id in ipairs(vim.api.nvim_list_wins()) do
pcall(vim.api.nvim_win_close, win_id, true)
end

for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
pcall(vim.api.nvim_buf_delete, buffer, { force = true })
end

vim.cmd([[silent! tabonly!]])
vim.cmd([[silent! tabclose!]])

if not ok then
error(err)
end
end

--- Run normal mode commands without mappings
Expand Down

0 comments on commit a53951a

Please sign in to comment.