Skip to content

Commit 5e40ea8

Browse files
committed
Handle multiple identical diagnostics in YcmShowDetailedDiagnostic popup
If a line for which detailed diagnostics are requested contains more than a single diagnostic with the same message, YCM will try `options.pop( 'col' )` more than once. We do not need to really iterate through the diagnostics once we have found the first one that is a match. If there's only one diag with the matching message, looping beyond that diagnostic is just a waste of time. If there's multiple diagnostics with the same message, it does not matter which one we display in the popup. Hence, the added break at the end of the loop.
1 parent c55e732 commit 5e40ea8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

python/ycm/youcompleteme.py

+1
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ def ShowDetailedDiagnostic( self, message_in_popup ):
868868
'textprop': prop[ 'type' ],
869869
} )
870870
options.pop( 'col' )
871+
break
871872
vim.eval( f'{ popup_func }( { json.dumps( lines ) }, '
872873
f'{ json.dumps( options ) } )' )
873874
else:

test/diagnostics.test.vim

+18
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,21 @@ function! Test_ShowDetailedDiagnostic_Popup_MultilineDiagFromStartOfLine()
446446

447447
%bwipe!
448448
endfunction
449+
450+
function! Test_ShowDetailedDiagnostic_Popup_MultipleDiagsPerLine_SameMessage()
451+
let f = tempname() . '.cc'
452+
execut 'edit' f
453+
call setline( 1, [ 'void f(){a;a;}', ] )
454+
call youcompleteme#test#setup#WaitForInitialParse( {} )
455+
456+
call WaitForAssert( {->
457+
\ assert_true(
458+
\ py3eval(
459+
\ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
460+
\ ) ) } )
461+
462+
YcmShowDetailedDiagnostic popup
463+
call assert_equal( 1, len( popup_list() ) )
464+
call feedkeys( "i\<Esc>", 'xt' )
465+
call assert_equal( 0, len( popup_list() ) )
466+
endfunction

0 commit comments

Comments
 (0)