Skip to content

Commit c55e732

Browse files
authored
Merge pull request #4218 from bstaletic/detailed-diag-popup-part2-electric-boogaloo
[READY] Take care of start column in multiline diags for detailed diag popups
2 parents 2b33bf3 + 06aa107 commit c55e732

File tree

2 files changed

+77
-54
lines changed

2 files changed

+77
-54
lines changed

python/ycm/vimsupport.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,22 @@ def GetTextPropertyForDiag( buffer_number, line_number, diag ):
288288
end_line = end[ 'line_num' ]
289289
if start_line == end_line:
290290
length = end[ 'column_num' ] - start[ 'column_num' ]
291+
column = start[ 'column_num' ]
291292
elif start_line == line_number:
292293
# -1 switches to 0-based indexing.
293294
current_line_len = len( vim.buffers[ buffer_number ][ line_number - 1 ] )
294295
# +2 includes the start columnand accounts for properties at the end of line
295296
# covering \n as well.
296297
length = current_line_len - start[ 'column_num' ] + 2
298+
column = start[ 'column_num' ]
297299
elif end_line == line_number:
298300
length = end[ 'column_num' ] - 1
301+
column = 1
299302
else:
300303
# -1 switches to 0-based indexing.
301304
# +1 accounts for properties at the end of line covering \n as well.
302305
length = len( vim.buffers[ buffer_number ][ line_number - 1 ] ) + 1
306+
column = 1
303307
if diag[ 'kind' ] == 'ERROR':
304308
property_name = 'YcmErrorProperty'
305309
else:
@@ -309,7 +313,7 @@ def GetTextPropertyForDiag( buffer_number, line_number, diag ):
309313
f'{{ "bufnr": { buffer_number }, '
310314
f'"types": [ "{ property_name }" ] }} )' )
311315
return next( filter(
312-
lambda p: start[ 'column_num' ] == int( p[ 'col' ] ) and
316+
lambda p: column == int( p[ 'col' ] ) and
313317
length == int( p[ 'length' ] ),
314318
vim_props ) )
315319
else:

test/diagnostics.test.vim

+72-53
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function! SetUp()
66
let g:ycm_log_level = 'DEBUG'
77
let g:ycm_always_populate_location_list = 1
88
let g:ycm_enable_semantic_highlighting = 1
9+
let g:ycm_auto_hover = ''
910

1011
" diagnostics take ages
1112
let g:ycm_test_min_delay = 7
@@ -348,15 +349,15 @@ function! Test_ShowDetailedDiagnostic_Popup_WithCharacters()
348349
%bwipe!
349350
endfunction
350351

351-
function! Test_ShowDetailedDiagnostic_Popup_MultilineDiag()
352+
function! Test_ShowDetailedDiagnostic_Popup_MultilineDiagNotFromStartOfLine()
352353
let f = tempname() . '.cc'
353354
execut 'edit' f
354355
call setline( 1, [
355356
\ 'int main () {',
356-
\ 'const int &&',
357-
\ ' /* */',
358-
\ ' rd = 1;',
359-
\ 'rd = 4;',
357+
\ ' int a \',
358+
\ '=\',
359+
\ '=',
360+
\ '3;',
360361
\ '}',
361362
\ ] )
362363
call youcompleteme#test#setup#WaitForInitialParse( {} )
@@ -367,62 +368,80 @@ function! Test_ShowDetailedDiagnostic_Popup_MultilineDiag()
367368
\ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
368369
\ ) ) } )
369370

370-
" Start of multiline diagnostic.
371-
call cursor( [ 2, 1 ] )
372-
YcmShowDetailedDiagnostic popup
371+
call test_override( 'char_avail', 1 )
373372

374-
let popup_location = screenpos( bufwinid( '%' ), 3, 13 )
375-
let id = popup_locate( popup_location[ 'row' ], popup_location[ 'col' ] )
376-
call assert_notequal( 0, id, "Couldn't find popup!" )
373+
for cursor_pos in [ [ 2, 9 ], [ 3, 1], [ 4, 1 ] ]
374+
call cursor( cursor_pos )
375+
YcmShowDetailedDiagnostic popup
376+
377+
call assert_equal( len( popup_list() ), 1 )
378+
let id = popup_list()[ 0 ]
379+
call assert_notequal( 0, id, "Couldn't find popup!" )
380+
call assert_equal( [ 3, 10 ], win_screenpos( id ) )
381+
382+
call youcompleteme#test#popup#CheckPopupPosition( id, {
383+
\ 'visible': 1,
384+
\ 'col': 10,
385+
\ 'line': 3,
386+
\ } )
387+
call assert_match(
388+
\ "^Invalid '==' at end of declaration; did you mean '='?.*",
389+
\ getbufline( winbufnr(id), 1, '$' )[ 0 ] )
390+
" From vim's test_popupwin.vim
391+
" trigger the check for last_cursormoved by going into insert mode
392+
call feedkeys( "ji\<Esc>", 'xt' )
393+
call assert_equal( {}, popup_getpos( id ) )
394+
endfor
377395

378-
call youcompleteme#test#popup#CheckPopupPosition( id, {
379-
\ 'visible': 1,
380-
\ 'col': 13,
381-
\ 'line': 3,
382-
\ } )
383-
call assert_match(
384-
\ "^Variable 'rd' declared const here.*",
385-
\ getbufline( winbufnr(id), 1, '$' )[ 0 ] )
386-
387-
" Middle of multiline diagnostic.
388-
call cursor( [ 3, 9 ] )
389-
YcmShowDetailedDiagnostic popup
396+
call test_override( 'ALL', 0 )
390397

391-
let popup_location = screenpos( bufwinid( '%' ), 3, 13 )
392-
let id = popup_locate( popup_location[ 'row' ], popup_location[ 'col' ] )
393-
call assert_notequal( 0, id, "Couldn't find popup!" )
398+
%bwipe!
399+
endfunction
394400

395-
" End of multiline diagnostic.
396-
call youcompleteme#test#popup#CheckPopupPosition( id, {
397-
\ 'visible': 1,
398-
\ 'col': 13,
399-
\ 'line': 3,
400-
\ } )
401-
call assert_match(
402-
\ "^Variable 'rd' declared const here.*",
403-
\ getbufline( winbufnr(id), 1, '$' )[ 0 ] )
401+
function! Test_ShowDetailedDiagnostic_Popup_MultilineDiagFromStartOfLine()
402+
let f = tempname() . '.cc'
403+
execut 'edit' f
404+
call setline( 1, [
405+
\ 'int main () {',
406+
\ 'const int &&',
407+
\ ' /* */',
408+
\ ' rd = 1;',
409+
\ 'rd = 4;',
410+
\ '}',
411+
\ ] )
412+
call youcompleteme#test#setup#WaitForInitialParse( {} )
404413

405-
call cursor( [ 4, 5 ] )
406-
YcmShowDetailedDiagnostic popup
414+
call WaitForAssert( {->
415+
\ assert_true(
416+
\ py3eval(
417+
\ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
418+
\ ) ) } )
407419

408-
let popup_location = screenpos( bufwinid( '%' ), 3, 13 )
409-
let id = popup_locate( popup_location[ 'row' ], popup_location[ 'col' ] )
410-
call assert_notequal( 0, id, "Couldn't find popup!" )
420+
call test_override( 'char_avail', 1 )
411421

412-
call youcompleteme#test#popup#CheckPopupPosition( id, {
413-
\ 'visible': 1,
414-
\ 'col': 13,
415-
\ 'line': 3,
416-
\ } )
417-
call assert_match(
418-
\ "^Variable 'rd' declared const here.*",
419-
\ getbufline( winbufnr(id), 1, '$' )[ 0 ] )
422+
for cursor_pos in [ [ 2, 1 ], [ 3, 9 ], [ 4, 5 ] ]
423+
call cursor( cursor_pos )
424+
YcmShowDetailedDiagnostic popup
425+
426+
call assert_equal( 1, len( popup_list() ) )
427+
let id = popup_list()[ 0 ]
428+
call assert_notequal( 0, id, "Couldn't find popup!" )
429+
call assert_equal( [ 3, 13 ], win_screenpos( id ) )
430+
431+
call youcompleteme#test#popup#CheckPopupPosition( id, {
432+
\ 'visible': 1,
433+
\ 'col': 13,
434+
\ 'line': 3,
435+
\ } )
436+
call assert_match(
437+
\ "^Variable 'rd' declared const here.*",
438+
\ getbufline( winbufnr(id), 1, '$' )[ 0 ] )
439+
" From vim's test_popupwin.vim
440+
" trigger the check for last_cursormoved by going into insert mode
441+
call feedkeys( "ji\<Esc>ki\<Esc>", 'xt' )
442+
call assert_equal( {}, popup_getpos( id ) )
443+
endfor
420444

421-
" From vim's test_popupwin.vim
422-
" trigger the check for last_cursormoved by going into insert mode
423-
call test_override( 'char_avail', 1 )
424-
call feedkeys( "ji\<Esc>", 'xt' )
425-
call assert_equal( {}, popup_getpos( id ) )
426445
call test_override( 'ALL', 0 )
427446

428447
%bwipe!

0 commit comments

Comments
 (0)