From 2bf3bd5cac6f525a2844d80b76b2b1614eb03b10 Mon Sep 17 00:00:00 2001 From: "Spencer G. Jones" Date: Wed, 12 Feb 2014 12:18:58 -0700 Subject: [PATCH 1/3] Update OmniSharpServer to latest to pickup cf35aeab and 53ea4d7fb5 --- python/ycm/completers/cs/OmniSharpServer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ycm/completers/cs/OmniSharpServer b/python/ycm/completers/cs/OmniSharpServer index ee198be6..53ea4d7f 160000 --- a/python/ycm/completers/cs/OmniSharpServer +++ b/python/ycm/completers/cs/OmniSharpServer @@ -1 +1 @@ -Subproject commit ee198be6f06d39cef84b0817e0b88d3e08cbc477 +Subproject commit 53ea4d7fb5190fa118ff36cdf1037644b4a2fc9f From 5b5e182194994696e48859a29e80293bc2a3fec1 Mon Sep 17 00:00:00 2001 From: "Spencer G. Jones" Date: Wed, 19 Feb 2014 09:48:22 -0700 Subject: [PATCH 2/3] Use new Omnisharp Server ready command --- python/ycm/completers/cs/cs_completer.py | 12 ++++++++++++ python/ycm/server/tests/get_completions_test.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/python/ycm/completers/cs/cs_completer.py b/python/ycm/completers/cs/cs_completer.py index 03c51566..68af3304 100755 --- a/python/ycm/completers/cs/cs_completer.py +++ b/python/ycm/completers/cs/cs_completer.py @@ -69,6 +69,7 @@ class CsharpCompleter( Completer ): 'StopServer', 'RestartServer', 'ServerRunning', + 'ServerReady', 'GoToDefinition', 'GoToDeclaration', 'GoToDefinitionElseDeclaration' ] @@ -95,6 +96,8 @@ class CsharpCompleter( Completer ): return self._StartServer( request_data ) elif command == 'ServerRunning': return self._ServerIsRunning() + elif command == 'ServerReady': + return self._ServerIsReady() elif command in [ 'GoToDefinition', 'GoToDeclaration', 'GoToDefinitionElseDeclaration' ]: @@ -221,6 +224,15 @@ class CsharpCompleter( Completer ): return False + def _ServerIsReady( self ): + """ Check if our OmniSharp server is ready """ + try: + return bool( self._omnisharp_port and + self._GetResponse( '/checkreadystatus', silent = True ) ) + except: + return False + + def _ServerLocation( self ): return 'http://localhost:' + str( self._omnisharp_port ) diff --git a/python/ycm/server/tests/get_completions_test.py b/python/ycm/server/tests/get_completions_test.py index 174ed03b..55e267d5 100644 --- a/python/ycm/server/tests/get_completions_test.py +++ b/python/ycm/server/tests/get_completions_test.py @@ -73,7 +73,7 @@ def GetCompletions_CsCompleter_Works_test(): while True: result = app.post_json( '/run_completer_command', BuildRequest( completer_target = 'filetype_default', - command_arguments = ['ServerRunning'], + command_arguments = ['ServerReady'], filetype = 'cs' ) ).json if result: break From ec96a021a41c582f03511f7fa6161826b44c617c Mon Sep 17 00:00:00 2001 From: "Spencer G. Jones" Date: Wed, 19 Feb 2014 11:17:52 -0700 Subject: [PATCH 3/3] Refactor cs_completer to reduce complexity --- python/ycm/completers/cs/cs_completer.py | 49 ++++++++++++------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/python/ycm/completers/cs/cs_completer.py b/python/ycm/completers/cs/cs_completer.py index 68af3304..4ec15e98 100755 --- a/python/ycm/completers/cs/cs_completer.py +++ b/python/ycm/completers/cs/cs_completer.py @@ -39,6 +39,17 @@ class CsharpCompleter( Completer ): A Completer that uses the Omnisharp server as completion engine. """ + subcommands = { + 'StartServer': (lambda self, request_data: self._StartServer( request_data )), + 'StopServer': (lambda self, request_data: self._StopServer()), + 'RestartServer': (lambda self, request_data: self._RestartServer( request_data )), + 'ServerRunning': (lambda self, request_data: self._ServerIsRunning()), + 'ServerReady': (lambda self, request_data: self._ServerIsReady()), + 'GoToDefinition': (lambda self, request_data: self._GoToDefinition( request_data )), + 'GoToDeclaration': (lambda self, request_data: self._GoToDefinition( request_data )), + 'GoToDefinitionElseDeclaration': (lambda self, request_data: self._GoToDefinition( request_data )) + } + def __init__( self, user_options ): super( CsharpCompleter, self ).__init__( user_options ) self._omnisharp_port = None @@ -65,14 +76,7 @@ class CsharpCompleter( Completer ): def DefinedSubcommands( self ): - return [ 'StartServer', - 'StopServer', - 'RestartServer', - 'ServerRunning', - 'ServerReady', - 'GoToDefinition', - 'GoToDeclaration', - 'GoToDefinitionElseDeclaration' ] + return CsharpCompleter.subcommands.keys() def OnFileReadyToParse( self, request_data ): @@ -86,23 +90,11 @@ class CsharpCompleter( Completer ): raise ValueError( self.UserCommandsHelpMessage() ) command = arguments[ 0 ] - if command == 'StartServer': - return self._StartServer( request_data ) - elif command == 'StopServer': - return self._StopServer() - elif command == 'RestartServer': - if self._ServerIsRunning(): - self._StopServer() - return self._StartServer( request_data ) - elif command == 'ServerRunning': - return self._ServerIsRunning() - elif command == 'ServerReady': - return self._ServerIsReady() - elif command in [ 'GoToDefinition', - 'GoToDeclaration', - 'GoToDefinitionElseDeclaration' ]: - return self._GoToDefinition( request_data ) - raise ValueError( self.UserCommandsHelpMessage() ) + if command in CsharpCompleter.subcommands: + command_lamba = CsharpCompleter.subcommands[ command ] + return command_lamba( self, request_data ) + else: + raise ValueError( self.UserCommandsHelpMessage() ) def DebugInfo( self ): @@ -184,6 +176,13 @@ class CsharpCompleter( Completer ): self._logger.info( 'Stopping OmniSharp server' ) + def _RestartServer ( self, request_data ): + """ Restarts the OmniSharp server """ + if self._ServerIsRunning(): + self._StopServer() + return self._StartServer( request_data ) + + def _GetCompletions( self, request_data ): """ Ask server for completions """ completions = self._GetResponse( '/autocomplete',