Refactor cs_completer to reduce complexity
This commit is contained in:
parent
5b5e182194
commit
ec96a021a4
@ -39,6 +39,17 @@ class CsharpCompleter( Completer ):
|
|||||||
A Completer that uses the Omnisharp server as completion engine.
|
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 ):
|
def __init__( self, user_options ):
|
||||||
super( CsharpCompleter, self ).__init__( user_options )
|
super( CsharpCompleter, self ).__init__( user_options )
|
||||||
self._omnisharp_port = None
|
self._omnisharp_port = None
|
||||||
@ -65,14 +76,7 @@ class CsharpCompleter( Completer ):
|
|||||||
|
|
||||||
|
|
||||||
def DefinedSubcommands( self ):
|
def DefinedSubcommands( self ):
|
||||||
return [ 'StartServer',
|
return CsharpCompleter.subcommands.keys()
|
||||||
'StopServer',
|
|
||||||
'RestartServer',
|
|
||||||
'ServerRunning',
|
|
||||||
'ServerReady',
|
|
||||||
'GoToDefinition',
|
|
||||||
'GoToDeclaration',
|
|
||||||
'GoToDefinitionElseDeclaration' ]
|
|
||||||
|
|
||||||
|
|
||||||
def OnFileReadyToParse( self, request_data ):
|
def OnFileReadyToParse( self, request_data ):
|
||||||
@ -86,22 +90,10 @@ class CsharpCompleter( Completer ):
|
|||||||
raise ValueError( self.UserCommandsHelpMessage() )
|
raise ValueError( self.UserCommandsHelpMessage() )
|
||||||
|
|
||||||
command = arguments[ 0 ]
|
command = arguments[ 0 ]
|
||||||
if command == 'StartServer':
|
if command in CsharpCompleter.subcommands:
|
||||||
return self._StartServer( request_data )
|
command_lamba = CsharpCompleter.subcommands[ command ]
|
||||||
elif command == 'StopServer':
|
return command_lamba( self, request_data )
|
||||||
return self._StopServer()
|
else:
|
||||||
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() )
|
raise ValueError( self.UserCommandsHelpMessage() )
|
||||||
|
|
||||||
|
|
||||||
@ -184,6 +176,13 @@ class CsharpCompleter( Completer ):
|
|||||||
self._logger.info( 'Stopping OmniSharp server' )
|
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 ):
|
def _GetCompletions( self, request_data ):
|
||||||
""" Ask server for completions """
|
""" Ask server for completions """
|
||||||
completions = self._GetResponse( '/autocomplete',
|
completions = self._GetResponse( '/autocomplete',
|
||||||
|
Loading…
Reference in New Issue
Block a user