Skip to content

Commit d44f61c

Browse files
committed
Improve debug experience.
1 parent 58e5401 commit d44f61c

File tree

5 files changed

+42
-35
lines changed

5 files changed

+42
-35
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DEVELOPMENT.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
[rust]: https://www.rust-lang.org
55

66
# Development
7+
Put those settings inside vimrc,
8+
```vim
9+
let g:LanguageClient_devel = 1 "Use rust debug build
10+
let g:LanguageClient_loggingLevel = 'DEBUG' "Use highest logging level
11+
```
12+
713
1. Make necessary changes.
814
1. Build. `make` to build, format and run [clippy], or `make build` to run build only.
915
1. Verify changes.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ instructions.
8080

8181
# Language Servers
8282

83-
Please see <http://langserver.org> and/or <https://github.com/Microsoft/language-server-protocol/wiki/Protocol-Implementations>.
83+
Please see <http://langserver.org> and/or <https://microsoft.github.io/language-server-protocol/implementors/servers/>.
8484

8585
# Documentation
8686

plugin/LanguageClient.vim

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
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
118123
endfunction
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
138148
elseif 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
144157
else
145158
echoerr 'Not supported: not nvim nor vim with +job.'
146159
endif
@@ -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
417428
endfunction
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
436445
endfunction
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
454461
endfunction
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
472477
endfunction
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
497500
endfunction
498501

@@ -549,10 +552,6 @@ function! LanguageClient_exit() abort
549552
\ })
550553
endfunction
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.
557556
function! s:Expand(exp) abort
558557
let l:result = expand(a:exp)

tests/data/vimrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set nocompatible
2+
13
let s:root = expand('<sfile>:p:h:h:h')
24
execute 'set runtimepath+=' . s:root
35

@@ -6,11 +8,11 @@ set runtimepath+=$HOME/.fzf
68
set noswapfile
79
set hidden
810

9-
let $LANGUAGECLIENT_DEBUG = 1
11+
let g:LanguageClient_devel = 1
12+
let g:LanguageClient_loggingLevel = 'DEBUG'
1013
let g:LanguageClient_serverCommands = {
1114
\ 'javascript': ['javascript-typescript-stdio'],
1215
\ }
1316
let g:LanguageClient_selectionUI = 'location-list'
14-
let g:LanguageClient_loggingLevel = 'DEBUG'
1517

1618
autocmd BufReadPost *.rs setlocal filetype=rust

0 commit comments

Comments
 (0)