@@ -159,10 +159,13 @@ function! s:set_virtual_text(params) abort
159
159
endfunction
160
160
161
161
function ! s: place_virtual_text (server, diagnostics_response, bufnr ) abort
162
+ let l: line_props = {}
163
+
162
164
let l: linecount = s: Buffer .get_line_count (a: bufnr )
163
165
for l: item in lsp#utils#iteratable (a: diagnostics_response [' params' ][' diagnostics' ])
164
166
let l: line = lsp#utils#position#lsp_line_to_vim (a: bufnr , l: item [' range' ][' start' ])
165
- let l: name = get (s: severity_sign_names_mapping , get (l: item , ' severity' , 3 ), ' LspError' )
167
+ let l: severity = get (l: item , ' severity' , 3 )
168
+ let l: name = get (s: severity_sign_names_mapping , l: severity , ' LspError' )
166
169
let l: text = g: lsp_diagnostics_virtual_text_prefix . l: item [' message' ]
167
170
168
171
" Some language servers report an unexpected EOF one line past the end
@@ -179,16 +182,30 @@ function! s:place_virtual_text(server, diagnostics_response, bufnr) abort
179
182
" it's an error to add virtual text on lines that don't exist
180
183
" anymore due to async processing, just skip such diagnostics
181
184
if l: line <= l: linecount
185
+ if g: lsp_diagnostics_virtual_text_tidy && has_key (l: line_props , l: line )
186
+ " Replace the existing virtual text with the one that has higher severity
187
+ if l: severity <= l: line_props [l: line ][' severity' ]
188
+ call prop_remove ({' id' : l: line_props [l: line ][' prop_id' ]}, l: line )
189
+ else
190
+ continue
191
+ endif
192
+ endif
193
+
182
194
let l: type = ' vim_lsp_' . l: name . ' _virtual_text'
183
195
call prop_remove ({' all' : v: true , ' type' : l: type , ' bufnr' : a: bufnr }, l: line )
184
- call prop_add (
196
+ let l: prop_id = prop_add (
185
197
\ l: line , 0 ,
186
198
\ {
187
199
\ ' type' : l: type , ' text' : l: text , ' bufnr' : a: bufnr ,
188
200
\ ' text_align' : g: lsp_diagnostics_virtual_text_align ,
189
201
\ ' text_padding_left' : g: lsp_diagnostics_virtual_text_padding_left ,
190
202
\ ' text_wrap' : g: lsp_diagnostics_virtual_text_wrap ,
191
203
\ })
204
+
205
+ let l: line_props [l: line ] = {
206
+ \ ' prop_id' : l: prop_id ,
207
+ \ ' severity' : l: severity ,
208
+ \ }
192
209
endif
193
210
endif
194
211
endfor
0 commit comments