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 Oct 2, 2024
1 parent fec78d9 commit 52346b1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,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 @@ -145,7 +149,12 @@ function configs.__newindex(t, config_name, config_def)
if #M.manager:clients() == 0 then
return true
end
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 52346b1

Please sign in to comment.