@@ -159,10 +159,13 @@ function! s:set_virtual_text(params) abort
159159endfunction
160160
161161function ! s: place_virtual_text (server, diagnostics_response, bufnr ) abort
162+ let l: line_props = {}
163+
162164 let l: linecount = s: Buffer .get_line_count (a: bufnr )
163165 for l: item in lsp#utils#iteratable (a: diagnostics_response [' params' ][' diagnostics' ])
164166 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' )
166169 let l: text = g: lsp_diagnostics_virtual_text_prefix . l: item [' message' ]
167170
168171 " 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
179182 " it's an error to add virtual text on lines that don't exist
180183 " anymore due to async processing, just skip such diagnostics
181184 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+
182194 let l: type = ' vim_lsp_' . l: name . ' _virtual_text'
183195 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 (
185197 \ l: line , 0 ,
186198 \ {
187199 \ ' type' : l: type , ' text' : l: text , ' bufnr' : a: bufnr ,
188200 \ ' text_align' : g: lsp_diagnostics_virtual_text_align ,
189201 \ ' text_padding_left' : g: lsp_diagnostics_virtual_text_padding_left ,
190202 \ ' text_wrap' : g: lsp_diagnostics_virtual_text_wrap ,
191203 \ })
204+
205+ let l: line_props [l: line ] = {
206+ \ ' prop_id' : l: prop_id ,
207+ \ ' severity' : l: severity ,
208+ \ }
192209 endif
193210 endif
194211 endfor
0 commit comments