Skip to content

Commit

Permalink
fix: check buffer validity in scheduled callbacks
Browse files Browse the repository at this point in the history
It's possible for the buffer an autocommand triggers on to be wiped out
later in the same event loop.
  • Loading branch information
Diomendius committed Oct 5, 2024
1 parent 52346b1 commit f34b21a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ function configs.__newindex(t, config_name, config_def)
-- Use vim.schedule() to ensure filetype detection happens first.
-- Sometimes, BufNewFile triggers before 'filetype' is set.
vim.schedule(function()
M.manager:try_add(opt.buf)
if api.nvim_buf_is_valid(opt.buf) then
M.manager:try_add(opt.buf)
end
end)
end,
group = lsp_group,
Expand Down Expand Up @@ -153,7 +155,9 @@ function configs.__newindex(t, config_name, config_def)
-- Use vim.schedule() to ensure filetype detection happens first.
-- Sometimes, BufNewFile triggers before 'filetype' is set.
vim.schedule(function()
M.manager:try_add_wrapper(arg.buf, root_dir)
if api.nvim_buf_is_valid(arg.buf) then
M.manager:try_add_wrapper(arg.buf, root_dir)
end
end)
end,
group = lsp_group,
Expand Down

0 comments on commit f34b21a

Please sign in to comment.