Skip to content

Commit

Permalink
Handle multiple identical diagnostics in YcmShowDetailedDiagnostic popup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bstaletic committed Feb 3, 2024
1 parent c55e732 commit 5e40ea8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/ycm/youcompleteme.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ def ShowDetailedDiagnostic( self, message_in_popup ):
'textprop': prop[ 'type' ],
} )
options.pop( 'col' )
break

Check warning on line 871 in python/ycm/youcompleteme.py

View check run for this annotation

Codecov / codecov/patch

python/ycm/youcompleteme.py#L871

Added line #L871 was not covered by tests
vim.eval( f'{ popup_func }( { json.dumps( lines ) }, '
f'{ json.dumps( options ) } )' )
else:
Expand Down
18 changes: 18 additions & 0 deletions test/diagnostics.test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,21 @@ function! Test_ShowDetailedDiagnostic_Popup_MultilineDiagFromStartOfLine()

%bwipe!
endfunction

function! Test_ShowDetailedDiagnostic_Popup_MultipleDiagsPerLine_SameMessage()
let f = tempname() . '.cc'
execut 'edit' f
call setline( 1, [ 'void f(){a;a;}', ] )
call youcompleteme#test#setup#WaitForInitialParse( {} )

call WaitForAssert( {->
\ assert_true(
\ py3eval(
\ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
\ ) ) } )

YcmShowDetailedDiagnostic popup
call assert_equal( 1, len( popup_list() ) )
call feedkeys( "i\<Esc>", 'xt' )
call assert_equal( 0, len( popup_list() ) )
endfunction

0 comments on commit 5e40ea8

Please sign in to comment.