Skip to content

Commit

Permalink
fix: ensure try_add() runs after filetype detection
Browse files Browse the repository at this point in the history
Sometimes, BufNewFile triggers before 'filetype' is set. Using
vim.schedule() should ensure filetype detection runs before the
callback.
  • Loading branch information
Diomendius committed Nov 7, 2023
1 parent 8368a88 commit 2ccafd1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ function configs.__newindex(t, config_name, config_def)
api.nvim_create_autocmd(event_conf.event, {
pattern = event_conf.pattern or '*',
callback = function(opt)
M.manager:try_add(opt.buf)
-- 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)
end)
end,
group = lsp_group,
desc = string.format(
Expand Down Expand Up @@ -139,7 +143,11 @@ function configs.__newindex(t, config_name, config_def)
api.nvim_create_autocmd({ 'BufReadPost', 'BufNewFile' }, {
pattern = fn.fnameescape(root_dir) .. '/*',
callback = function(arg)
M.manager:try_add_wrapper(arg.buf, root_dir)
-- 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)
end)
end,
group = lsp_group,
desc = string.format(
Expand Down

0 comments on commit 2ccafd1

Please sign in to comment.