Minor style fixes
This commit is contained in:
parent
66b70ee7f5
commit
33a05a4b42
@ -37,31 +37,36 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
|
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
super( CsharpCompleter, self ).__init__()
|
super( CsharpCompleter, self ).__init__()
|
||||||
self.OmniSharpPort = int( vimsupport.GetVariableValue(
|
self._omnisharp_port = int( vimsupport.GetVariableValue(
|
||||||
"g:ycm_csharp_server_port" ) )
|
"g:ycm_csharp_server_port" ) )
|
||||||
self.OmniSharpHost = 'http://localhost:' + str( self.OmniSharpPort )
|
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()
|
||||||
|
|
||||||
|
|
||||||
def OnVimLeave( self ):
|
def OnVimLeave( self ):
|
||||||
if self._ServerIsRunning():
|
if self._ServerIsRunning():
|
||||||
self._StopServer()
|
self._StopServer()
|
||||||
|
|
||||||
|
|
||||||
def SupportedFiletypes( self ):
|
def SupportedFiletypes( self ):
|
||||||
""" Just csharp """
|
""" Just csharp """
|
||||||
return [ 'cs' ]
|
return [ 'cs' ]
|
||||||
|
|
||||||
|
|
||||||
def ComputeCandidates( self, unused_query, unused_start_column ):
|
def ComputeCandidates( self, unused_query, unused_start_column ):
|
||||||
return [ { 'word': str( completion['CompletionText'] ),
|
return [ { 'word': str( completion[ 'CompletionText' ] ),
|
||||||
'menu': str( completion['DisplayText'] ),
|
'menu': str( completion[ 'DisplayText' ] ),
|
||||||
'info': str( completion['Description'] ) }
|
'info': str( completion[ 'Description' ] ) }
|
||||||
for completion in self._GetCompletions() ]
|
for completion in self._GetCompletions() ]
|
||||||
|
|
||||||
|
|
||||||
def DefinedSubcommands( self ):
|
def DefinedSubcommands( self ):
|
||||||
return [ 'StartServer',
|
return [ 'StartServer',
|
||||||
'StopServer',
|
'StopServer',
|
||||||
'RestartServer' ]
|
'RestartServer' ]
|
||||||
|
|
||||||
|
|
||||||
def OnUserCommand( self, arguments ):
|
def OnUserCommand( self, arguments ):
|
||||||
if not arguments:
|
if not arguments:
|
||||||
self.EchoUserCommandsHelpMessage()
|
self.EchoUserCommandsHelpMessage()
|
||||||
@ -77,55 +82,50 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
self._StopServer()
|
self._StopServer()
|
||||||
self._StartServer()
|
self._StartServer()
|
||||||
|
|
||||||
|
|
||||||
def _StartServer( self ):
|
def _StartServer( self ):
|
||||||
""" Start the OmniSharp server """
|
""" Start the OmniSharp server """
|
||||||
if not self._ServerIsRunning():
|
if not self._ServerIsRunning():
|
||||||
solutionfiles, folder = self._FindSolutionFiles()
|
solutionfiles, folder = _FindSolutionFiles()
|
||||||
|
|
||||||
if len( solutionfiles ) == 0:
|
if len( solutionfiles ) == 0:
|
||||||
vimsupport.PostVimMessage(
|
vimsupport.PostVimMessage(
|
||||||
'Error starting OmniSharp server: no solutionfile found' )
|
'Error starting OmniSharp server: no solutionfile found' )
|
||||||
return
|
return
|
||||||
elif len( solutionfiles ) == 1:
|
elif len( solutionfiles ) == 1:
|
||||||
solutionfile = solutionfiles[0]
|
solutionfile = solutionfiles[ 0 ]
|
||||||
else:
|
else:
|
||||||
choice = vimsupport.PresentDialog(
|
choice = vimsupport.PresentDialog(
|
||||||
"Which solutionfile should be loaded?",
|
"Which solutionfile should be loaded?",
|
||||||
[ str(i) + " " + s for i, s in enumerate( solutionfiles ) ] )
|
[ str( i ) + " " + solution for i, solution in
|
||||||
|
enumerate( solutionfiles ) ] )
|
||||||
if choice == -1:
|
if choice == -1:
|
||||||
vimsupport.PostVimMessage( 'OmniSharp not started' )
|
vimsupport.PostVimMessage( 'OmniSharp not started' )
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
solutionfile = solutionfiles[ choice ]
|
solutionfile = solutionfiles[ choice ]
|
||||||
|
|
||||||
omnisharp = os.path.join( os.path.abspath( os.path.dirname( __file__ ) ),
|
omnisharp = os.path.join(
|
||||||
'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe' )
|
os.path.abspath( os.path.dirname( __file__ ) ),
|
||||||
|
'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe' )
|
||||||
solutionfile = os.path.join ( folder, solutionfile )
|
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.OmniSharpPort )
|
command = [ omnisharp + ' -p ' + str( self._omnisharp_port ) + ' -s ' +
|
||||||
+ ' -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 )
|
||||||
|
|
||||||
|
|
||||||
def _StopServer( self ):
|
def _StopServer( self ):
|
||||||
""" Stop the OmniSharp server """
|
""" Stop the OmniSharp server """
|
||||||
self._GetResponse( '/stopserver' )
|
self._GetResponse( '/stopserver' )
|
||||||
|
|
||||||
|
|
||||||
def _ServerIsRunning( self ):
|
def _ServerIsRunning( self ):
|
||||||
""" Check if the OmniSharp server is running """
|
""" Check if the OmniSharp server is running """
|
||||||
return self._GetResponse( '/checkalivestatus', silent=True ) != None
|
return self._GetResponse( '/checkalivestatus', silent=True ) != None
|
||||||
|
|
||||||
def _FindSolutionFiles( self ):
|
|
||||||
folder = os.path.dirname( vim.current.buffer.name )
|
|
||||||
solutionfiles = glob.glob1( folder, '*.sln' )
|
|
||||||
while not solutionfiles:
|
|
||||||
lastfolder = folder
|
|
||||||
folder = os.path.dirname( folder )
|
|
||||||
if folder == lastfolder:
|
|
||||||
break
|
|
||||||
solutionfiles = glob.glob1( folder, '*.sln' )
|
|
||||||
return solutionfiles, folder
|
|
||||||
|
|
||||||
def _GetCompletions( self ):
|
def _GetCompletions( self ):
|
||||||
""" Ask server for completions """
|
""" Ask server for completions """
|
||||||
@ -139,15 +139,29 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
completions = self._GetResponse( '/autocomplete', parameters )
|
completions = self._GetResponse( '/autocomplete', parameters )
|
||||||
return completions if completions != None else []
|
return completions if completions != None else []
|
||||||
|
|
||||||
|
|
||||||
def _GetResponse( self, endPoint, parameters={}, silent = False ):
|
def _GetResponse( self, endPoint, parameters={}, silent = False ):
|
||||||
""" Handle communication with server """
|
""" Handle communication with server """
|
||||||
target = urlparse.urljoin( self.OmniSharpHost, endPoint )
|
target = urlparse.urljoin( self._omnisharp_host, endPoint )
|
||||||
parameters = urllib.urlencode( parameters )
|
parameters = urllib.urlencode( parameters )
|
||||||
try:
|
try:
|
||||||
response = urllib2.urlopen( target, parameters )
|
response = urllib2.urlopen( target, parameters )
|
||||||
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 '
|
vimsupport.PostVimMessage('OmniSharp : Could not connect to ' + target +
|
||||||
+ target + ': ' + str(e))
|
': ' + str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _FindSolutionFiles():
|
||||||
|
folder = os.path.dirname( vim.current.buffer.name )
|
||||||
|
solutionfiles = glob.glob1( folder, '*.sln' )
|
||||||
|
while not solutionfiles:
|
||||||
|
lastfolder = folder
|
||||||
|
folder = os.path.dirname( folder )
|
||||||
|
if folder == lastfolder:
|
||||||
|
break
|
||||||
|
solutionfiles = glob.glob1( folder, '*.sln' )
|
||||||
|
return solutionfiles, folder
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user