mirror of
https://github.com/prabirshrestha/vim-lsp.git
synced 2025-12-14 20:35:59 +01:00
* 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.
58 lines
2.0 KiB
VimL
58 lines
2.0 KiB
VimL
function! s:BuildConfigBlock(section, info) abort
|
|
let l:block = get(a:info, a:section, '')
|
|
if !empty(l:block)
|
|
return printf("### %s\n%s\n", a:section, l:block)
|
|
endif
|
|
return ''
|
|
endf
|
|
|
|
|
|
function! health#lsp#check() abort
|
|
call health#report_start('server status')
|
|
let l:server_status = lsp#collect_server_status()
|
|
|
|
let l:has_printed = v:false
|
|
for l:k in sort(keys(l:server_status))
|
|
let l:report = l:server_status[l:k]
|
|
|
|
let l:status_msg = printf('%s: %s', l:k, l:report.status)
|
|
if l:report.status == 'running'
|
|
call health#report_ok(l:status_msg)
|
|
elseif l:report.status == 'failed'
|
|
call health#report_error(l:status_msg, 'See :help g:lsp_log_verbose to debug server failure.')
|
|
else
|
|
call health#report_warn(l:status_msg)
|
|
endif
|
|
let l:has_printed = v:true
|
|
endfor
|
|
|
|
if !l:has_printed
|
|
call health#report_warn('no servers connected')
|
|
endif
|
|
|
|
for l:k in sort(keys(l:server_status))
|
|
call health#report_start(printf('server configuration: %s', l:k))
|
|
let l:report = l:server_status[l:k]
|
|
|
|
let l:msg = "\t\n"
|
|
let l:msg .= s:BuildConfigBlock('allowlist', l:report.info)
|
|
let l:msg .= s:BuildConfigBlock('blocklist', l:report.info)
|
|
let l:cfg = get(l:report.info, 'workspace_config', '')
|
|
if !empty(l:cfg)
|
|
if get(g:, 'loaded_scriptease', 0)
|
|
let l:cfg = scriptease#dump(l:cfg, {'width': &columns-1})
|
|
else
|
|
let l:cfg = json_encode(l:cfg)
|
|
" Add some whitespace to make it readable.
|
|
let l:cfg = substitute(l:cfg, '[,{(\[]', "&\n\t", 'g')
|
|
let l:cfg = substitute(l:cfg, '":', '& ', 'g')
|
|
let l:cfg = substitute(l:cfg, '\v[})\]]+', "\n&", 'g')
|
|
let l:cfg = substitute(l:cfg, '\n\s*\n', "\n", 'g')
|
|
endif
|
|
let l:msg .= printf("### workspace_config\n```json\n%s\n```", l:cfg)
|
|
endif
|
|
call health#report_info(l:msg)
|
|
endfor
|
|
endf
|
|
|