Skip to content

Commit 05bbb07

Browse files
authored
Merge pull request #4193 from bstaletic/hover-traceback
[READY] Stop auto hover timer if buffer changes or cursor moves
2 parents 1212def + 36a1a54 commit 05bbb07

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

autoload/youcompleteme.vim

+38-12
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,28 @@ function! s:OnFileSave()
760760
endfunction
761761

762762

763+
function! s:AbortAutohoverRequest() abort
764+
if g:ycm_auto_hover ==# 'CursorHold' && s:enable_hover
765+
let requests = copy( s:pollers.command.requests )
766+
for request_id in keys( requests )
767+
let request = requests[ request_id ]
768+
if request.origin == 'autohover'
769+
call remove( s:pollers.command.requests, request_id )
770+
call request.callback( '' )
771+
endif
772+
endfor
773+
endif
774+
endfunction
775+
776+
763777
function! s:OnBufferEnter()
764778
call s:StartMessagePoll()
765779
if !s:VisitedBufferRequiresReparse()
766780
return
767781
endif
768782

783+
call s:AbortAutohoverRequest()
784+
769785
call s:SetUpCompleteopt()
770786
call s:EnableCompletingInCurrentBuffer()
771787

@@ -966,6 +982,8 @@ function! s:OnCursorMovedNormalMode()
966982
return
967983
endif
968984

985+
call s:AbortAutohoverRequest()
986+
969987
py3 ycm_state.OnCursorMoved()
970988
endfunction
971989

@@ -1441,22 +1459,13 @@ function! youcompleteme#GetCommandResponse( ... ) abort
14411459
endfunction
14421460

14431461

1444-
function! youcompleteme#GetCommandResponseAsync( callback, ... ) abort
1445-
if !s:AllowedToCompleteInCurrentBuffer()
1446-
eval a:callback( '' )
1447-
return
1448-
endif
1449-
1450-
if !get( b:, 'ycm_completing' )
1451-
eval a:callback( '' )
1452-
return
1453-
endif
1454-
1462+
function! s:GetCommandResponseAsyncImpl( callback, origin, ... ) abort
14551463
let request_id = py3eval(
14561464
\ 'ycm_state.SendCommandRequestAsync( vim.eval( "a:000" ) )' )
14571465

14581466
let s:pollers.command.requests[ request_id ] = {
14591467
\ 'response_func': 'StringResponse',
1468+
\ 'origin': a:origin,
14601469
\ 'callback': a:callback
14611470
\ }
14621471
if s:pollers.command.id == -1
@@ -1466,6 +1475,21 @@ function! youcompleteme#GetCommandResponseAsync( callback, ... ) abort
14661475
endfunction
14671476

14681477

1478+
function! youcompleteme#GetCommandResponseAsync( callback, ... ) abort
1479+
if !s:AllowedToCompleteInCurrentBuffer()
1480+
eval a:callback( '' )
1481+
return
1482+
endif
1483+
1484+
if !get( b:, 'ycm_completing' )
1485+
eval a:callback( '' )
1486+
return
1487+
endif
1488+
1489+
call s:GetCommandResponseAsyncImpl( callback, 'extern', a:000 )
1490+
endfunction
1491+
1492+
14691493
function! youcompleteme#GetRawCommandResponseAsync( callback, ... ) abort
14701494
if !s:AllowedToCompleteInCurrentBuffer()
14711495
eval a:callback( { 'error': 'ycm not allowed in buffer' } )
@@ -1482,6 +1506,7 @@ function! youcompleteme#GetRawCommandResponseAsync( callback, ... ) abort
14821506

14831507
let s:pollers.command.requests[ request_id ] = {
14841508
\ 'response_func': 'Response',
1509+
\ 'origin': 'extern_raw',
14851510
\ 'callback': a:callback
14861511
\ }
14871512
if s:pollers.command.id == -1
@@ -1621,8 +1646,9 @@ if exists( '*popup_atcursor' )
16211646
return
16221647
endif
16231648

1624-
call youcompleteme#GetCommandResponseAsync(
1649+
call s:GetCommandResponseAsyncImpl(
16251650
\ function( 's:ShowHoverResult' ),
1651+
\ 'autohover',
16261652
\ b:ycm_hover.command )
16271653
endfunction
16281654

0 commit comments

Comments
 (0)