Skip to content

Commit

Permalink
Stop auto hover timer if buffer changes or cursor moves
Browse files Browse the repository at this point in the history
  • Loading branch information
bstaletic committed Feb 14, 2024
1 parent 1212def commit 36a1a54
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions autoload/youcompleteme.vim
Expand Up @@ -760,12 +760,28 @@ function! s:OnFileSave()
endfunction


function! s:AbortAutohoverRequest() abort
if g:ycm_auto_hover ==# 'CursorHold' && s:enable_hover
let requests = copy( s:pollers.command.requests )
for request_id in keys( requests )
let request = requests[ request_id ]
if request.origin == 'autohover'
call remove( s:pollers.command.requests, request_id )
call request.callback( '' )

Check warning on line 770 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L767-L770

Added lines #L767 - L770 were not covered by tests
endif
endfor
endif
endfunction


function! s:OnBufferEnter()
call s:StartMessagePoll()
if !s:VisitedBufferRequiresReparse()
return
endif

call s:AbortAutohoverRequest()

Check warning on line 783 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L783

Added line #L783 was not covered by tests

call s:SetUpCompleteopt()
call s:EnableCompletingInCurrentBuffer()

Expand Down Expand Up @@ -966,6 +982,8 @@ function! s:OnCursorMovedNormalMode()
return
endif

call s:AbortAutohoverRequest()

py3 ycm_state.OnCursorMoved()
endfunction

Expand Down Expand Up @@ -1441,22 +1459,13 @@ function! youcompleteme#GetCommandResponse( ... ) abort
endfunction


function! youcompleteme#GetCommandResponseAsync( callback, ... ) abort
if !s:AllowedToCompleteInCurrentBuffer()
eval a:callback( '' )
return
endif

if !get( b:, 'ycm_completing' )
eval a:callback( '' )
return
endif

function! s:GetCommandResponseAsyncImpl( callback, origin, ... ) abort
let request_id = py3eval(
\ 'ycm_state.SendCommandRequestAsync( vim.eval( "a:000" ) )' )

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


function! youcompleteme#GetCommandResponseAsync( callback, ... ) abort
if !s:AllowedToCompleteInCurrentBuffer()
eval a:callback( '' )
return

Check warning on line 1481 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L1479-L1481

Added lines #L1479 - L1481 were not covered by tests
endif

if !get( b:, 'ycm_completing' )
eval a:callback( '' )
return

Check warning on line 1486 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L1484-L1486

Added lines #L1484 - L1486 were not covered by tests
endif

call s:GetCommandResponseAsyncImpl( callback, 'extern', a:000 )

Check warning on line 1489 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L1489

Added line #L1489 was not covered by tests
endfunction


function! youcompleteme#GetRawCommandResponseAsync( callback, ... ) abort
if !s:AllowedToCompleteInCurrentBuffer()
eval a:callback( { 'error': 'ycm not allowed in buffer' } )
Expand All @@ -1482,6 +1506,7 @@ function! youcompleteme#GetRawCommandResponseAsync( callback, ... ) abort

let s:pollers.command.requests[ request_id ] = {
\ 'response_func': 'Response',
\ 'origin': 'extern_raw',
\ 'callback': a:callback
\ }
if s:pollers.command.id == -1
Expand Down Expand Up @@ -1621,8 +1646,9 @@ if exists( '*popup_atcursor' )
return
endif

call youcompleteme#GetCommandResponseAsync(
call s:GetCommandResponseAsyncImpl(
\ function( 's:ShowHoverResult' ),
\ 'autohover',
\ b:ycm_hover.command )
endfunction

Expand Down

0 comments on commit 36a1a54

Please sign in to comment.