Skip to content

Commit 054a8e9

Browse files
committed
Fix incorrect BufEnter handling (autozimu#1132)
1 parent 70a90a9 commit 054a8e9

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

plugin/LanguageClient.vim

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,33 @@ endfunction
153153
command! -nargs=* LanguageClientStart :call LanguageClient#startServer(<f-args>)
154154
command! LanguageClientStop call LanguageClient#shutdown()
155155

156-
function! s:ConfigureAutocmds()
157-
let l:commands = get(g:, 'LanguageClient_serverCommands', {})
158-
if !has_key(l:commands, &filetype)
159-
" skip setting autocmds if the filetype doesn't have a configured server command
156+
function! s:OnBufEnter()
157+
if !s:HasCommand()
158+
return
159+
endif
160+
161+
call LanguageClient#handleBufEnter()
162+
call s:ConfigureAutocmds()
163+
endfunction
164+
165+
function! s:OnFileType()
166+
if !s:HasCommand()
160167
return
161168
endif
162169

163170
call LanguageClient#handleFileType()
171+
call s:ConfigureAutocmds()
172+
endfunction
173+
174+
function! s:HasCommand()
175+
let l:commands = get(g:, 'LanguageClient_serverCommands', {})
176+
return has_key(l:commands, &filetype)
177+
endfunction
178+
179+
function! s:ConfigureAutocmds()
164180
augroup languageClient
165181
autocmd!
166182
autocmd BufNewFile <buffer> call LanguageClient#handleBufNewFile()
167-
autocmd BufEnter <buffer> call LanguageClient#handleBufEnter()
168183
autocmd BufWritePost <buffer> call LanguageClient#handleBufWritePost()
169184
autocmd BufDelete <buffer> call LanguageClient#handleBufDelete()
170185
autocmd TextChanged <buffer> call LanguageClient#handleTextChanged()
@@ -203,5 +218,6 @@ endfunction
203218

204219
augroup languageClient_fileType
205220
autocmd!
206-
autocmd FileType * call s:ConfigureAutocmds()
221+
autocmd FileType * call s:OnFileType()
222+
autocmd BufEnter * call s:OnBufEnter()
207223
augroup END

0 commit comments

Comments
 (0)