diff --git a/autoload/lsp/internal/diagnostics/highlights.vim b/autoload/lsp/internal/diagnostics/highlights.vim index 60f6bb4b..ddf4d7ec 100644 --- a/autoload/lsp/internal/diagnostics/highlights.vim +++ b/autoload/lsp/internal/diagnostics/highlights.vim @@ -163,18 +163,45 @@ function! s:place_highlights(server, diagnostics_response, bufnr) abort \ l:line - 1, l:highlight_start_col - 1, l:highlight_end_col == -1 ? -1 : l:highlight_end_col) endfor else - try - " TODO: need to check for valid range before calling prop_add - " See https://github.com/prabirshrestha/vim-lsp/pull/721 - silent! call prop_add(l:start_line, l:start_col, { - \ 'end_lnum': l:end_line, - \ 'end_col': l:end_col, - \ 'bufnr': a:bufnr, - \ 'type': s:get_prop_type_name(l:severity), - \ }) - catch - call lsp#log('diagnostics', 'place_highlights', 'prop_add', v:exception, v:throwpoint) - endtry + if l:start_line == l:end_line + try + " TODO: need to check for valid range before calling prop_add + " See https://github.com/prabirshrestha/vim-lsp/pull/721 + silent! call prop_add(l:start_line, l:start_col, { + \ 'end_col': l:end_col, + \ 'bufnr': a:bufnr, + \ 'type': s:get_prop_type_name(l:severity), + \ }) + catch + call lsp#log('diagnostics', 'place_highlights', 'prop_add', v:exception, v:throwpoint) + endtry + else + for l:line in range(l:start_line, l:end_line) + if l:line == l:start_line + let l:highlight_start_col = l:start_col + else + let l:highlight_start_col = 1 + endif + + if l:line == l:end_line + let l:highlight_end_col = l:end_col + else + let l:highlight_end_col = strlen(getbufline(a:bufnr, l:line, l:line)[0]) + 1 + endif + + try + " TODO: need to check for valid range before calling prop_add + " See https://github.com/prabirshrestha/vim-lsp/pull/721 + silent! call prop_add(l:line, l:highlight_start_col, { + \ 'end_col': l:highlight_end_col, + \ 'bufnr': a:bufnr, + \ 'type': s:get_prop_type_name(l:severity), + \ }) + catch + call lsp#log('diagnostics', 'place_highlights', 'prop_add', v:exception, v:throwpoint) + endtry + endfor + endif endif endfor endfunction