Skip to content

Commit 0c8fda7

Browse files
authored
Print workspace_config with :verbose LspStatus (#1279)
* Make verbose LspStatus show workspace config Need the trailing echo to ensure the next lsp server is on a new line. * Use pretty printing if available * checkhealth: Print server status and config Add initial checkhealth support. See https://github.com/rhysd/vim-healthcheck Lists server status, advice for failure, and lists workspace config to help debug issues or understand server state. Doesn't do much error detecting. * checkhealth: Print each server config as a section checkhealth doesn't allow a lot of formatting (no indentation), so it's hard to make the config output readable. Output each server as a separate section instead of one giant config block to make the start of each server easier to see.
1 parent 9d4dbf7 commit 0c8fda7

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ let g:lsp_log_file = expand('~/vim-lsp.log')
183183
let g:asyncomplete_log_file = expand('~/asyncomplete.log')
184184
```
185185

186+
You can get detailed status on your servers using `:CheckHealth` -- built into neovim or in a plugin on vim:
187+
188+
```vim
189+
if !has('nvim') | Plug 'rhysd/vim-healthcheck' | endif
190+
CheckHealth
191+
```
192+
186193
## Tests
187194

188195
[vim-themis](https://github.com/thinca/vim-themis) is used for testing. To run

autoload/health/lsp.vim

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function! s:BuildConfigBlock(section, info) abort
2+
let l:block = get(a:info, a:section, '')
3+
if !empty(l:block)
4+
return printf("### %s\n%s\n", a:section, l:block)
5+
endif
6+
return ''
7+
endf
8+
9+
10+
function! health#lsp#check() abort
11+
call health#report_start('server status')
12+
let l:server_status = lsp#collect_server_status()
13+
14+
let l:has_printed = v:false
15+
for l:k in sort(keys(l:server_status))
16+
let l:report = l:server_status[l:k]
17+
18+
let l:status_msg = printf('%s: %s', l:k, l:report.status)
19+
if l:report.status == 'running'
20+
call health#report_ok(l:status_msg)
21+
elseif l:report.status == 'failed'
22+
call health#report_error(l:status_msg, 'See :help g:lsp_log_verbose to debug server failure.')
23+
else
24+
call health#report_warn(l:status_msg)
25+
endif
26+
let l:has_printed = v:true
27+
endfor
28+
29+
if !l:has_printed
30+
call health#report_warn('no servers connected')
31+
endif
32+
33+
for l:k in sort(keys(l:server_status))
34+
call health#report_start(printf('server configuration: %s', l:k))
35+
let l:report = l:server_status[l:k]
36+
37+
let l:msg = "\t\n"
38+
let l:msg .= s:BuildConfigBlock('allowlist', l:report.info)
39+
let l:msg .= s:BuildConfigBlock('blocklist', l:report.info)
40+
let l:cfg = get(l:report.info, 'workspace_config', '')
41+
if !empty(l:cfg)
42+
if get(g:, 'loaded_scriptease', 0)
43+
let l:cfg = scriptease#dump(l:cfg, {'width': &columns-1})
44+
else
45+
let l:cfg = json_encode(l:cfg)
46+
" Add some whitespace to make it readable.
47+
let l:cfg = substitute(l:cfg, '[,{(\[]', "&\n\t", 'g')
48+
let l:cfg = substitute(l:cfg, '":', '& ', 'g')
49+
let l:cfg = substitute(l:cfg, '\v[})\]]+', "\n&", 'g')
50+
let l:cfg = substitute(l:cfg, '\n\s*\n', "\n", 'g')
51+
endif
52+
let l:msg .= printf("### workspace_config\n```json\n%s\n```", l:cfg)
53+
endif
54+
call health#report_info(l:msg)
55+
endfor
56+
endf
57+

autoload/lsp.vim

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,22 @@ let s:color_map = {
148148
\ 'not running': 'Comment'
149149
\}
150150

151-
" Print the current status of all servers (if called with no arguments)
151+
" Collect the current status of all servers
152+
function! lsp#collect_server_status() abort
153+
let l:results = {}
154+
for l:k in keys(s:servers)
155+
let l:status = s:server_status(l:k)
156+
" Copy to prevent callers from corrupting our config.
157+
let l:info = deepcopy(s:servers[l:k].server_info)
158+
let l:results[l:k] = {
159+
\ 'status': l:status,
160+
\ 'info': l:info,
161+
\ }
162+
endfor
163+
return l:results
164+
endfunction
165+
166+
" Print the current status of all servers
152167
function! lsp#print_server_status() abort
153168
for l:k in sort(keys(s:servers))
154169
let l:status = s:server_status(l:k)
@@ -157,6 +172,15 @@ function! lsp#print_server_status() abort
157172
echon l:status
158173
echohl None
159174
echo ''
175+
if &verbose
176+
let l:cfg = { 'workspace_config': s:servers[l:k].server_info.workspace_config }
177+
if get(g:, 'loaded_scriptease', 0)
178+
call scriptease#pp_command(0, -1, l:cfg)
179+
else
180+
echo json_encode(l:cfg)
181+
endif
182+
echo ''
183+
endif
160184
endfor
161185
endfunction
162186

doc/vim-lsp.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CONTENTS *vim-lsp-contents*
1111
Configure |vim-lsp-configure|
1212
vim-lsp-settings |vim-lsp-settings_plugin|
1313
Wiki |vim-lsp-configure-wiki|
14+
Health Check |vim-lsp-healthcheck|
1415
Options |vim-lsp-options|
1516
g:lsp_auto_enable |g:lsp_auto_enable|
1617
g:lsp_preview_keep_focus |g:lsp_preview_keep_focus|
@@ -270,6 +271,13 @@ to automatically register various language servers.
270271
Plug 'prabirshrestha/vim-lsp'
271272
Plug 'mattn/vim-lsp-settings'
272273
274+
HEALTH CHECK *vim-lsp-healthcheck*
275+
vim-lsp supports the |:CheckHealth| command which can be useful when debugging
276+
lsp configuration issues.
277+
278+
This command is included in neovim and implemented in vim with the
279+
[vim-healthcheck](https://github.com/rhysd/vim-healthcheck) plugin.
280+
273281
WIKI *vim-lsp-configure-wiki*
274282
For documentation on how to configure other language servers refer
275283
to https://github.com/prabirshrestha/vim-lsp/wiki/Servers
@@ -1778,7 +1786,9 @@ Servers may choose to return empty results if the search query is empty.
17781786

17791787
LspStatus *:LspStatus*
17801788

1781-
Prints the status of all registered servers.
1789+
Prints the status of all registered servers. Use `:verbose LspStatus` to
1790+
additionally show each server's workspace_config.
1791+
See also |vim-lsp-healthcheck|.
17821792

17831793
LspStopServer *:LspStopServer*
17841794

0 commit comments

Comments
 (0)