@@ -153,18 +153,33 @@ endfunction
153153command ! -nargs =* LanguageClientStart :call LanguageClient#startServer (<f-args> )
154154command ! 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
204219augroup languageClient_fileType
205220 autocmd !
206- autocmd FileType * call s: ConfigureAutocmds ()
221+ autocmd FileType * call s: OnFileType ()
222+ autocmd BufEnter * call s: OnBufEnter ()
207223augroup END
0 commit comments