diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 9acff345..4caa7fad 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -728,23 +728,8 @@ function! s:InvokeCompletion() endfunction -exec s:python_until_eof -def GetCompletionsInner(): - request = ycm_state.GetCurrentCompletionRequest() - request.Start() - while not request.Done(): - if bool( int( vim.eval( 'complete_check()' ) ) ): - return { 'words' : [], 'refresh' : 'always'} - - results = base.AdjustCandidateInsertionText( request.Response() ) - return { 'words' : results, 'refresh' : 'always' } -EOF - - function! s:GetCompletions() - exec s:python_command "results = GetCompletionsInner()" - let results = s:Pyeval( 'results' ) - return results + return s:Pyeval( 'ycm_state.GetCompletions()' ) endfunction diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 920dc108..6ebf1315 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -506,7 +506,10 @@ def PresentDialog( message, choices, default_choice_index = 0 ): EscapeForVim( ToUnicode( message ) ), EscapeForVim( ToUnicode( "\n" .join( choices ) ) ), default_choice_index + 1 ) - return int( vim.eval( to_eval ) ) - 1 + try: + return GetIntValue( to_eval ) - 1 + except KeyboardInterrupt: + return -1 def Confirm( message ): @@ -554,9 +557,9 @@ def SelectFromList( prompt, items ): # See :help input() for explanation of the use of inputsave() and inpput # restore(). It is done in try/finally in case vim.eval ever throws an # exception (such as KeyboardInterrupt) - selected = int( vim.eval( "inputlist( " - + json.dumps( vim_items ) - + " )" ) ) - 1 + selected = GetIntValue( "inputlist( " + json.dumps( vim_items ) + " )" ) - 1 + except KeyboardInterrupt: + selected = -1 finally: vim.eval( 'inputrestore()' ) diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 423fbf7b..33a324ff 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -32,7 +32,7 @@ import signal import base64 from subprocess import PIPE from tempfile import NamedTemporaryFile -from ycm import paths, vimsupport +from ycm import base, paths, vimsupport from ycmd import utils from ycmd import server_utils from ycmd.request_wrap import RequestWrap @@ -234,6 +234,20 @@ class YouCompleteMe( object ): return self._latest_completion_request + def GetCompletions( self ): + request = self.GetCurrentCompletionRequest() + request.Start() + while not request.Done(): + try: + if vimsupport.GetBoolValue( 'complete_check()' ): + return { 'words' : [], 'refresh' : 'always' } + except KeyboardInterrupt: + return { 'words' : [], 'refresh' : 'always' } + + results = base.AdjustCandidateInsertionText( request.Response() ) + return { 'words' : results, 'refresh' : 'always' } + + def SendCommandRequest( self, arguments, completer ): if self.IsServerAlive(): return SendCommandRequest( arguments, completer )