More style fixes + more status reporting to :mes
This commit is contained in:
parent
c5a76301e8
commit
7aa01b9c09
@ -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,7 +89,11 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
|
|
||||||
def _StartServer( self ):
|
def _StartServer( self ):
|
||||||
""" Start the OmniSharp server """
|
""" Start the OmniSharp server """
|
||||||
if not self._ServerIsRunning():
|
if self._ServerIsRunning():
|
||||||
|
vimsupport.PostVimMessage(
|
||||||
|
'Server already running, not starting it again.' )
|
||||||
|
return
|
||||||
|
|
||||||
solutionfiles, folder = _FindSolutionFiles()
|
solutionfiles, folder = _FindSolutionFiles()
|
||||||
|
|
||||||
if len( solutionfiles ) == 0:
|
if len( solutionfiles ) == 0:
|
||||||
@ -108,18 +116,26 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
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 )
|
|
||||||
|
if not os.path.isfile( omnisharp ):
|
||||||
|
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 has to be provided as one string for some reason
|
||||||
command = [ omnisharp + ' -p ' + str( self._omnisharp_port ) + ' -s ' +
|
command = [ omnisharp + ' -p ' + str( self._omnisharp_port ) + ' -s ' +
|
||||||
solutionfile ]
|
solutionfile ]
|
||||||
|
|
||||||
with open( os.devnull, "w" ) as fnull:
|
with open( os.devnull, 'w' ) as fnull:
|
||||||
subprocess.Popen( command, stdout = fnull, stderr = fnull, shell=True )
|
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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user