diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 5138c177..adbd60c0 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -482,9 +482,13 @@ export def AddFile(bnr: number): void if lspserver.ready BufferInit(lspserver.id, bnr) else - augroup LSPBufferAutocmds - exe $'autocmd User LspServerReady_{lspserver.id} ++once BufferInit({lspserver.id}, {bnr})' - augroup END + # Lsp server is not ready yet. Initialize the lsp state for this buffer + # when the server is ready. + autocmd_add([{group: 'LSPBufferAutocmds', + event: 'User', + pattern: $'LspServerReady_{lspserver.id}', + once: true, + cmd: $'BufferInit({lspserver.id}, {bnr})'}]) endif endfor enddef diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 3d91520f..7304b003 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -132,8 +132,8 @@ def ServerInitReply(lspserver: dict, initResult: dict): void exe $'doautocmd User LspServerReady{lspserver.name}' endif # Used internally, and shouldn't be used by users - if exists($'#User#LspServerReady_{lspserver.id}') - exe $'doautocmd User LspServerReady_{lspserver.id}' + if exists($'#LSPBufferAutocmds#User#LspServerReady_{lspserver.id}') + exe $'doautocmd LSPBufferAutocmds User LspServerReady_{lspserver.id}' endif # set the server debug trace level