diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index b43df82a39..9841022006 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -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() @@ -966,6 +982,8 @@ function! s:OnCursorMovedNormalMode() return endif + call s:AbortAutohoverRequest() + py3 ycm_state.OnCursorMoved() endfunction @@ -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 @@ -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' } ) @@ -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 @@ -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