Skip to content

Commit 6f3d2d4

Browse files
authored
Update diagnostics when document open (#727)
1 parent 651bccf commit 6f3d2d4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

autoload/lsp.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ function! s:on_text_document_did_open() abort
209209
if getbufvar(l:buf, '&buftype') ==# 'terminal' | return | endif
210210
if getcmdwintype() !=# '' | return | endif
211211
call lsp#log('s:on_text_document_did_open()', l:buf, &filetype, getcwd(), lsp#utils#get_buffer_uri(l:buf))
212+
213+
" Some language server notify diagnostics to the buffer that has not been loaded yet.
214+
" This diagnostics was stored `autoload/lsp/ui/vim/diagnostics.vim` but not highlighted.
215+
" So we should refresh highlights when buffer opened.
216+
call lsp#ui#vim#diagnostics#force_refresh(l:buf)
217+
212218
for l:server_name in lsp#get_whitelisted_servers(l:buf)
213219
call s:ensure_flush(l:buf, l:server_name, function('s:fire_lsp_buffer_enabled', [l:server_name, l:buf]))
214220
endfor

autoload/lsp/ui/vim/diagnostics.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ function! lsp#ui#vim#diagnostics#handle_text_document_publish_diagnostics(server
2020
call lsp#ui#vim#signs#set(a:server_name, a:data)
2121
endfunction
2222

23+
function! lsp#ui#vim#diagnostics#force_refresh(bufnr) abort
24+
let l:data = lsp#ui#vim#diagnostics#get_document_diagnostics(a:bufnr)
25+
if !empty(l:data)
26+
for [l:server_name, l:response] in items(l:data)
27+
call lsp#ui#vim#virtual#set(l:server_name, l:response)
28+
call lsp#ui#vim#highlights#set(l:server_name, l:response)
29+
call lsp#ui#vim#diagnostics#textprop#set(l:server_name, l:response)
30+
call lsp#ui#vim#signs#set(l:server_name, l:response)
31+
endfor
32+
endif
33+
endfunction
34+
35+
function! lsp#ui#vim#diagnostics#get_document_diagnostics(bufnr) abort
36+
return get(s:diagnostics, lsp#utils#get_buffer_uri(a:bufnr), {})
37+
endfunction
38+
2339
function! lsp#ui#vim#diagnostics#document_diagnostics() abort
2440
if !g:lsp_diagnostics_enabled
2541
call lsp#utils#error('Diagnostics manually disabled -- g:lsp_diagnostics_enabled = 0')

0 commit comments

Comments
 (0)