Skip to content

Commit

Permalink
Make all subcommands async
Browse files Browse the repository at this point in the history
  • Loading branch information
bstaletic committed Aug 26, 2023
1 parent 4f1dcf4 commit 68bc068
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.
36 changes: 26 additions & 10 deletions autoload/youcompleteme.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1507,10 +1507,18 @@ function! s:PollCommands( timer_id ) abort
let poll_again = 1
continue
else
let result = py3eval( 'ycm_state.GetCommandRequest( '
\ . 'int( vim.eval( "request_id" ) ) ).'
\ . request.response_func
\ . '()' )
if len( request.response_func_args ) == 0
let result = py3eval( 'ycm_state.GetCommandRequest( '
\ . 'int( vim.eval( "request_id" ) ) ).'
\ . request.response_func
\ . '()' )
else
let result = py3eval( 'ycm_state.GetCommandRequest( '
\ . 'int( vim.eval( "request_id" ) ) ).'
\ . request.response_func
\ . '(' . request.response_func_args . ')' )
let request.response_func_args = ''
endif
endif

" This request is done
Expand All @@ -1526,13 +1534,21 @@ function! s:PollCommands( timer_id ) abort
endfunction


function! s:EmptyCallback( result ) abort
endfunction


function! s:CompleterCommand( mods, count, line1, line2, ... )
py3 ycm_state.SendCommandRequest(
\ vim.eval( 'a:000' ),
\ vim.eval( 'a:mods' ),
\ vimsupport.GetBoolValue( 'a:count != -1' ),
\ vimsupport.GetIntValue( 'a:line1' ),
\ vimsupport.GetIntValue( 'a:line2' ) )
let request_id = py3eval( 'ycm_state.SendCommandRequestAsync( vim.eval( "a:000" ), vimsupport.GetBoolValue( "a:count != -1" ), vimsupport.GetIntValue( "a:line1" ), vimsupport.GetIntValue( "a:line2" ), False )' )
let s:pollers.command.requests[ request_id ] = {
\ 'response_func': 'RunPostCommandActionsIfNeeded',
\ 'response_func_args': '"' . a:mods . '","' . g:ycm_goto_buffer_command . '"',
\ 'callback': function( 's:EmptyCallback' )
\ }
if s:pollers.command.id == -1
let s:pollers.command.id = timer_start( s:pollers.command.wait_milliseconds,
\ function( 's:PollCommands' ) )
endif
endfunction


Expand Down
12 changes: 0 additions & 12 deletions python/ycm/client/command_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,6 @@ def SendCommandRequestAsync( arguments, extra_data = None, silent = True ):
return request


def SendCommandRequest( arguments,
modifiers,
buffer_command = DEFAULT_BUFFER_COMMAND,
extra_data = None ):
request = SendCommandRequestAsync( arguments,
extra_data = extra_data,
silent = False )
# Block here to get the response
request.RunPostCommandActionsIfNeeded( modifiers, buffer_command )
return request.Response()


def GetCommandResponse( arguments, extra_data = None ):
request = SendCommandRequestAsync( arguments,
extra_data = extra_data,
Expand Down
38 changes: 12 additions & 26 deletions python/ycm/youcompleteme.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
from ycm.client.ycmd_keepalive import YcmdKeepalive
from ycm.client.base_request import BaseRequest, BuildRequestData
from ycm.client.completer_available_request import SendCompleterAvailableRequest
from ycm.client.command_request import ( SendCommandRequest,
SendCommandRequestAsync,
from ycm.client.command_request import ( SendCommandRequestAsync,
GetCommandResponse )
from ycm.client.completion_request import CompletionRequest
from ycm.client.resolve_completion_request import ResolveCompletionItem
Expand Down Expand Up @@ -403,25 +402,6 @@ def _GetCommandRequestArguments( self,
return final_arguments, extra_data



def SendCommandRequest( self,
arguments,
modifiers,
has_range,
start_line,
end_line ):
final_arguments, extra_data = self._GetCommandRequestArguments(
arguments,
has_range,
start_line,
end_line )
return SendCommandRequest(
final_arguments,
modifiers,
self._user_options[ 'goto_buffer_command' ],
extra_data )


def GetCommandResponse( self, arguments ):
final_arguments, extra_data = self._GetCommandRequestArguments(
arguments,
Expand All @@ -431,18 +411,24 @@ def GetCommandResponse( self, arguments ):
return GetCommandResponse( final_arguments, extra_data )


def SendCommandRequestAsync( self, arguments ):
def SendCommandRequestAsync( self,
arguments,
has_range = False,
start_line = 0,
end_line = 0,
silent = True ):
final_arguments, extra_data = self._GetCommandRequestArguments(
arguments,
False,
0,
0 )
has_range,
start_line,
end_line )

request_id = self._next_command_request_id
self._next_command_request_id += 1
self._command_requests[ request_id ] = SendCommandRequestAsync(
final_arguments,
extra_data )
extra_data,
silent )
return request_id


Expand Down

0 comments on commit 68bc068

Please sign in to comment.