Skip to content

Commit

Permalink
fix: consider attaching when editing new file
Browse files Browse the repository at this point in the history
BufReadPost does not trigger when editing a nonexistent file, so
language servers would not automatically attach when editing a new file
if autostart was disabled or if the server had no associated filetypes.
This fixes that by adding BufNewFile to autocommands hooked to
BufReadPost.
  • Loading branch information
Diomendius committed Jul 9, 2023
1 parent deade69 commit 0aa499d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function configs.__newindex(t, config_name, config_def)

if config.autostart == true then
local event_conf = config.filetypes and { event = 'FileType', pattern = config.filetypes }
or { event = 'BufReadPost' }
or { event = { 'BufReadPost', 'BufNewFile' } }
api.nvim_create_autocmd(event_conf.event, {
pattern = event_conf.pattern or '*',
callback = function(opt)
Expand Down Expand Up @@ -136,7 +136,7 @@ function configs.__newindex(t, config_name, config_def)
end

if root_dir then
api.nvim_create_autocmd('BufReadPost', {
api.nvim_create_autocmd({ 'BufReadPost', 'BufNewFile' }, {
pattern = fn.fnameescape(root_dir) .. '/*',
callback = function(arg)
M.manager.try_add_wrapper(arg.buf, root_dir)
Expand Down

0 comments on commit 0aa499d

Please sign in to comment.