From 86f0e8d65582d4c4803c5c7c51f72776772bc72d Mon Sep 17 00:00:00 2001 From: Martin Asquino Date: Sat, 7 Nov 2020 14:37:22 +0000 Subject: [PATCH] Fix incorrect BufEnter handling --- plugin/LanguageClient.vim | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/plugin/LanguageClient.vim b/plugin/LanguageClient.vim index d3a18460..eea638ad 100644 --- a/plugin/LanguageClient.vim +++ b/plugin/LanguageClient.vim @@ -153,18 +153,33 @@ endfunction command! -nargs=* LanguageClientStart :call LanguageClient#startServer() command! LanguageClientStop call LanguageClient#shutdown() -function! s:ConfigureAutocmds() - let l:commands = get(g:, 'LanguageClient_serverCommands', {}) - if !has_key(l:commands, &filetype) - " skip setting autocmds if the filetype doesn't have a configured server command +function! s:OnBufEnter() + if !s:HasCommand() + return + endif + + call LanguageClient#handleBufEnter() + call s:ConfigureAutocmds() +endfunction + +function! s:OnFileType() + if !s:HasCommand() return endif call LanguageClient#handleFileType() + call s:ConfigureAutocmds() +endfunction + +function! s:HasCommand() + let l:commands = get(g:, 'LanguageClient_serverCommands', {}) + return has_key(l:commands, &filetype) +endfunction + +function! s:ConfigureAutocmds() augroup languageClient autocmd! autocmd BufNewFile call LanguageClient#handleBufNewFile() - autocmd BufEnter call LanguageClient#handleBufEnter() autocmd BufWritePost call LanguageClient#handleBufWritePost() autocmd BufDelete call LanguageClient#handleBufDelete() autocmd TextChanged call LanguageClient#handleTextChanged() @@ -203,5 +218,6 @@ endfunction augroup languageClient_fileType autocmd! - autocmd FileType * call s:ConfigureAutocmds() + autocmd FileType * call s:OnFileType() + autocmd BufEnter * call s:OnBufEnter() augroup END