Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[READY] Stop auto hover timer if buffer changes or cursor moves #4193

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions autoload/youcompleteme.vim
Original file line number Diff line number Diff line change
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( '' )
endif
endfor
endif
endfunction


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

call s:AbortAutohoverRequest()

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
endif

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

call s:GetCommandResponseAsyncImpl( callback, 'extern', a:000 )
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