1- if $LANGUAGECLIENT_DEBUG
1+ function ! s: Echoerr (message) abort
2+ echohl Error | echomsg a: message | echohl None
3+ endfunction
4+
5+ function ! s: Debug (message) abort
6+ if g: LanguageClient_loggingLevel == ? ' INFO' || g: LanguageClient_loggingLevel == ? ' DEBUG'
7+ call s: Echoerr (a: message )
8+ endif
9+ endfunction
10+
11+ if exists (' LanguageClient_devel' )
212 if empty ($CARGO_TARGET_DIR )
313 let s: command = [expand (' <sfile>:p:h:h' ) . ' /target/debug/languageclient' ]
414 else
@@ -69,9 +79,7 @@ function! s:HandleMessage(job, lines, event) abort
6979 \ }
7080 \ }))
7181 endif
72- if $LANGUAGECLIENT_DEBUG
73- call s: Echoerr (string (v: exception ))
74- endif
82+ call s: Debug (string (v: exception ))
7583 endtry
7684 elseif has_key (l: message , ' result' )
7785 let l: id = get (l: message , ' id' )
@@ -103,17 +111,14 @@ function! s:HandleMessage(job, lines, event) abort
103111 endif
104112 endwhile
105113 elseif a: event == ' stderr'
106- if $LANGUAGECLIENT_DEBUG
107- call s: Echoerr (' LanguageClient stderr: ' . string (a: lines ))
108- endif
114+ call s: Echoerr (' languageclient stderr: ' . string (a: lines ))
109115 elseif a: event == ' exit'
110- if a: lines !=# ' 0 '
111- call s: Echoerr ( ' languageclient exited with: ' . string ( a: lines ))
116+ if type ( a: lines) == v: t_number && a: lines == 0
117+ return
112118 endif
119+ call s: Echoerr (' languageclient exited with: ' . string (a: lines ))
113120 else
114- if $LANGUAGECLIENT_DEBUG
115- call s: Echoerr (' Unknown event: ' . a: event )
116- endif
121+ call s: Debug (' languageclient unknown event: ' . a: event )
117122 endif
118123endfunction
119124
@@ -135,12 +140,20 @@ if has('nvim')
135140 \ ' on_stderr' : function (' s:HandleMessage' ),
136141 \ ' on_exit' : function (' s:HandleMessage' ),
137142 \ })
143+ if s: job == 0
144+ call s: Echoerr (' languageclient: Invalid arguments!' )
145+ elseif s: job == -1
146+ call s: Echoerr (' languageclient: Not executable!' )
147+ endif
138148elseif has (' job' )
139149 let s: job = job_start (s: command , {
140150 \ ' out_cb' : function (' s:HandleStdoutVim' ),
141151 \ ' err_cb' : function (' s:HandleStderrVim' ),
142152 \ ' exit_cb' : function (' s:HandleExitVim' ),
143153 \ })
154+ if job_status (s: job ) != ' run'
155+ s: Echoerr (' languageclient: job failed to start or died!' )
156+ endif
144157else
145158 echoerr ' Not supported: not nvim nor vim with +job.'
146159endif
@@ -410,9 +423,7 @@ function! LanguageClient_handleBufReadPost() abort
410423 \ ' filename' : s: Expand (' %:p' ),
411424 \ })
412425 catch /.*/
413- if $LANGUAGECLIENT_DEBUG
414- call s: Echoerr (" Caught " . string (v: exception ))
415- endif
426+ call s: Debug (' languageclient caught exception: ' . string (v: exception ))
416427 endtry
417428endfunction
418429
@@ -429,9 +440,7 @@ function! LanguageClient_handleTextChanged() abort
429440 \ ' text' : getbufline (' ' , 1 , ' $' ),
430441 \ })
431442 catch /.*/
432- if $LANGUAGECLIENT_DEBUG
433- call s: Echoerr (" Caught " . string (v: exception ))
434- endif
443+ call s: Debug (' languageclient caught exception: ' . string (v: exception ))
435444 endtry
436445endfunction
437446
@@ -447,9 +456,7 @@ function! LanguageClient_handleBufWritePost() abort
447456 \ ' filename' : s: Expand (' %:p' ),
448457 \ })
449458 catch /.*/
450- if $LANGUAGECLIENT_DEBUG
451- call s: Echoerr (" Caught " . string (v: exception ))
452- endif
459+ call s: Debug (' languageclient caught exception: ' . string (v: exception ))
453460 endtry
454461endfunction
455462
@@ -465,9 +472,7 @@ function! LanguageClient_handleBufDelete() abort
465472 \ ' filename' : s: Expand (' %:p' ),
466473 \ })
467474 catch /.*/
468- if $LANGUAGECLIENT_DEBUG
469- call s: Echoerr (" Caught " . string (v: exception ))
470- endif
475+ call s: Debug (' languageclient caught exception: ' . string (v: exception ))
471476 endtry
472477endfunction
473478
@@ -490,9 +495,7 @@ function! LanguageClient_handleCursorMoved() abort
490495 \ ' line' : line (' .' ) - 1 ,
491496 \ })
492497 catch /.*/
493- if $LANGUAGECLIENT_DEBUG
494- call s: Echoerr (" Caught " . string (v: exception ))
495- endif
498+ call s: Debug (' languageclient caught exception: ' . string (v: exception ))
496499 endtry
497500endfunction
498501
@@ -549,10 +552,6 @@ function! LanguageClient_exit() abort
549552 \ })
550553endfunction
551554
552- function ! s: Echoerr (message) abort
553- echohl Error | echomsg a: message | echohl None
554- endfunction
555-
556555" When editing a [No Name] file, neovim reports filename as "", while vim reports null.
557556function ! s: Expand (exp ) abort
558557 let l: result = expand (a: exp )
0 commit comments