More style fixes + more status reporting to :mes

This commit is contained in:
Strahinja Val Markovic 2013-07-17 19:29:43 -07:00
parent c5a76301e8
commit 7aa01b9c09

View File

@ -30,6 +30,10 @@ import json
import subprocess import subprocess
SERVER_NOT_FOUND_MSG = ( 'OmniSharp server binary not found at {0}. ' +
'Did you compile it? You can do so by running ' +
'"./install.sh --omnisharp_completer".' )
class CsharpCompleter( ThreadedCompleter ): class CsharpCompleter( ThreadedCompleter ):
""" """
A Completer that uses the Omnisharp server as completion engine. A Completer that uses the Omnisharp server as completion engine.
@ -38,9 +42,9 @@ class CsharpCompleter( ThreadedCompleter ):
def __init__( self ): def __init__( self ):
super( CsharpCompleter, self ).__init__() super( CsharpCompleter, self ).__init__()
self._omnisharp_port = int( vimsupport.GetVariableValue( self._omnisharp_port = int( vimsupport.GetVariableValue(
"g:ycm_csharp_server_port" ) ) 'g:ycm_csharp_server_port' ) )
self._omnisharp_host = 'http://localhost:' + str( self._omnisharp_port ) self._omnisharp_host = 'http://localhost:' + str( self._omnisharp_port )
if vimsupport.GetBoolValue( "g:ycm_auto_start_csharp_server" ): if vimsupport.GetBoolValue( 'g:ycm_auto_start_csharp_server' ):
self._StartServer() self._StartServer()
@ -85,41 +89,53 @@ class CsharpCompleter( ThreadedCompleter ):
def _StartServer( self ): def _StartServer( self ):
""" Start the OmniSharp server """ """ Start the OmniSharp server """
if not self._ServerIsRunning(): if self._ServerIsRunning():
solutionfiles, folder = _FindSolutionFiles() vimsupport.PostVimMessage(
'Server already running, not starting it again.' )
return
if len( solutionfiles ) == 0: solutionfiles, folder = _FindSolutionFiles()
vimsupport.PostVimMessage(
'Error starting OmniSharp server: no solutionfile found' ) if len( solutionfiles ) == 0:
vimsupport.PostVimMessage(
'Error starting OmniSharp server: no solutionfile found' )
return
elif len( solutionfiles ) == 1:
solutionfile = solutionfiles[ 0 ]
else:
choice = vimsupport.PresentDialog(
"Which solutionfile should be loaded?",
[ str( i ) + " " + solution for i, solution in
enumerate( solutionfiles ) ] )
if choice == -1:
vimsupport.PostVimMessage( 'OmniSharp not started' )
return return
elif len( solutionfiles ) == 1:
solutionfile = solutionfiles[ 0 ]
else: else:
choice = vimsupport.PresentDialog( solutionfile = solutionfiles[ choice ]
"Which solutionfile should be loaded?",
[ str( i ) + " " + solution for i, solution in
enumerate( solutionfiles ) ] )
if choice == -1:
vimsupport.PostVimMessage( 'OmniSharp not started' )
return
else:
solutionfile = solutionfiles[ choice ]
omnisharp = os.path.join( omnisharp = os.path.join(
os.path.abspath( os.path.dirname( __file__ ) ), os.path.abspath( os.path.dirname( __file__ ) ),
'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe' ) 'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe' )
solutionfile = os.path.join ( folder, solutionfile )
# command has to be provided as one string for some reason
command = [ omnisharp + ' -p ' + str( self._omnisharp_port ) + ' -s ' +
solutionfile ]
with open( os.devnull, "w" ) as fnull: if not os.path.isfile( omnisharp ):
subprocess.Popen( command, stdout = fnull, stderr = fnull, shell=True ) vimsupport.PostVimMessage( SERVER_NOT_FOUND_MSG.format( omnisharp ) )
return
solutionfile = os.path.join( folder, solutionfile )
# command has to be provided as one string for some reason
command = [ omnisharp + ' -p ' + str( self._omnisharp_port ) + ' -s ' +
solutionfile ]
with open( os.devnull, 'w' ) as fnull:
subprocess.Popen( command, stdout = fnull, stderr = fnull, shell=True )
vimsupport.PostVimMessage( 'Starting OmniSharp server')
def _StopServer( self ): def _StopServer( self ):
""" Stop the OmniSharp server """ """ Stop the OmniSharp server """
self._GetResponse( '/stopserver' ) self._GetResponse( '/stopserver' )
vimsupport.PostVimMessage( 'Stopping OmniSharp server')
def _ServerIsRunning( self ): def _ServerIsRunning( self ):
@ -149,8 +165,8 @@ class CsharpCompleter( ThreadedCompleter ):
return json.loads( response.read() ) return json.loads( response.read() )
except Exception as e: except Exception as e:
if not silent: if not silent:
vimsupport.PostVimMessage('OmniSharp : Could not connect to ' + target + vimsupport.PostVimMessage(
': ' + str(e)) 'OmniSharp : Could not connect to ' + target + ': ' + str( e ) )
return None return None