Skip to content

Commit

Permalink
fix: check validity of buffer in deferred callbacks
Browse files Browse the repository at this point in the history
Buffer may have been :bwipeout-ed by user before the callback runs.
  • Loading branch information
tomtomjhj committed Apr 16, 2023
1 parent 093caa3 commit 4f36dee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lua/aerial/backends/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ M.set_symbols = function(bufnr, items, ctx)
-- We need that autocmd to complete first so that it reallocates the existing aerial windows,
-- thus the defer. It's a bit of a hack :/
vim.defer_fn(function()
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end
window.maybe_open_automatic(bufnr)
end, 15)
end
Expand Down
3 changes: 3 additions & 0 deletions lua/aerial/backends/lsp/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ M.symbol_callback = function(_err, result, context, _config)
vim.defer_fn(function()
local r = results[bufnr]
results[bufnr] = nil
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end
M.handle_symbols(r, bufnr, client.name)
end, 100)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/aerial/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ M.flash_highlight = function(bufnr, lnum, durationMs, hl_group)
end
local ns = vim.api.nvim_buf_add_highlight(bufnr, 0, hl_group, lnum - 1, 0, -1)
local remove_highlight = function()
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
pcall(vim.api.nvim_buf_clear_namespace, bufnr, ns, 0, -1)
end
vim.defer_fn(remove_highlight, durationMs)
end
Expand Down
3 changes: 3 additions & 0 deletions lua/aerial/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ local function create_aerial_buffer(bufnr)
callback = function(params)
-- Defer it so we have time to set window options and variables on the float first
vim.defer_fn(function()
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end
render.update_aerial_buffer(aer_bufnr)
M.update_all_positions(bufnr, 0)
M.center_symbol_in_view(bufnr)
Expand Down

0 comments on commit 4f36dee

Please sign in to comment.