Update diagnostics when document open (#727)

This commit is contained in:
hrsh7th
2020-02-25 11:08:49 +09:00
committed by GitHub
parent 651bccfab8
commit 6f3d2d4e79
2 changed files with 22 additions and 0 deletions
+6
View File
@@ -209,6 +209,12 @@ function! s:on_text_document_did_open() abort
if getbufvar(l:buf, '&buftype') ==# 'terminal' | return | endif
if getcmdwintype() !=# '' | return | endif
call lsp#log('s:on_text_document_did_open()', l:buf, &filetype, getcwd(), lsp#utils#get_buffer_uri(l:buf))
" Some language server notify diagnostics to the buffer that has not been loaded yet.
" This diagnostics was stored `autoload/lsp/ui/vim/diagnostics.vim` but not highlighted.
" So we should refresh highlights when buffer opened.
call lsp#ui#vim#diagnostics#force_refresh(l:buf)
for l:server_name in lsp#get_whitelisted_servers(l:buf)
call s:ensure_flush(l:buf, l:server_name, function('s:fire_lsp_buffer_enabled', [l:server_name, l:buf]))
endfor
+16
View File
@@ -20,6 +20,22 @@ function! lsp#ui#vim#diagnostics#handle_text_document_publish_diagnostics(server
call lsp#ui#vim#signs#set(a:server_name, a:data)
endfunction
function! lsp#ui#vim#diagnostics#force_refresh(bufnr) abort
let l:data = lsp#ui#vim#diagnostics#get_document_diagnostics(a:bufnr)
if !empty(l:data)
for [l:server_name, l:response] in items(l:data)
call lsp#ui#vim#virtual#set(l:server_name, l:response)
call lsp#ui#vim#highlights#set(l:server_name, l:response)
call lsp#ui#vim#diagnostics#textprop#set(l:server_name, l:response)
call lsp#ui#vim#signs#set(l:server_name, l:response)
endfor
endif
endfunction
function! lsp#ui#vim#diagnostics#get_document_diagnostics(bufnr) abort
return get(s:diagnostics, lsp#utils#get_buffer_uri(a:bufnr), {})
endfunction
function! lsp#ui#vim#diagnostics#document_diagnostics() abort
if !g:lsp_diagnostics_enabled
call lsp#utils#error('Diagnostics manually disabled -- g:lsp_diagnostics_enabled = 0')