From faa6cf3f36f7c769b52dafd51eec7ed478c66728 Mon Sep 17 00:00:00 2001 From: Chiel92 Date: Fri, 28 Jun 2013 21:15:05 +0200 Subject: [PATCH] several fixes --- python/ycm/completers/cs/cs_completer.py | 38 +++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/python/ycm/completers/cs/cs_completer.py b/python/ycm/completers/cs/cs_completer.py index 4090d76e..bb9c0d3f 100755 --- a/python/ycm/completers/cs/cs_completer.py +++ b/python/ycm/completers/cs/cs_completer.py @@ -27,6 +27,7 @@ import urllib2 import urllib import urlparse import json +import subprocess class CsharpCompleter( ThreadedCompleter ): @@ -36,12 +37,13 @@ class CsharpCompleter( ThreadedCompleter ): def __init__( self ): super( CsharpCompleter, self ).__init__() - self.OmniSharp_host = 2000 - self._StartServer() + self.OmniSharpPort = 2000 + self.OmniSharpHost = 'http://localhost:' + str( self.OmniSharpPort ) + #self._StartServer() def SupportedFiletypes( self ): """ Just csharp """ - return ['cs'] + return [ 'cs' ] def ComputeCandidates( self, unused_query, unused_start_column ): return [ { 'word': str( completion['CompletionText'] ), @@ -50,8 +52,8 @@ class CsharpCompleter( ThreadedCompleter ): for completion in self._GetCompletions() ] def DefinedSubcommands( self ): - return [ "StartServer", - "StopServer" ] + return [ 'StartServer', + 'StopServer' ] def OnUserCommand( self, arguments ): if not arguments: @@ -69,27 +71,33 @@ class CsharpCompleter( ThreadedCompleter ): if ( not self._ServerIsRunning() ): # Find the solution file folder = os.path.dirname( vim.current.buffer.name ) - solutionfiles = glob.glob1( folder, "*.sln" ) + solutionfiles = glob.glob1( folder, '*.sln' ) while not solutionfiles: lastfolder = folder # Traverse up a level folder = os.path.dirname( folder ) if folder == lastfolder: break - solutionfiles = glob.glob1( folder, "*.sln" ) + solutionfiles = glob.glob1( folder, '*.sln' ) if len( solutionfiles ) == 1: - pass # start server here + omnisharp = os.path.join( os.path.abspath( os.path.dirname( __file__ ) ), './OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe' ) + solutionfile = os.path.abspath ( solutionfiles[0] ) + command = [ omnisharp, '-p ' + str( self.OmniSharpPort ), '-s ' + solutionfile ] + # Why doesn't this work properly? + # When starting manually in seperate console, everything works + # Maybe due to bothering stdin/stdout redirecting? + subprocess.Popen( command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) else: - pass # some other stuff, like notifying + vimsupport.PostVimMessage( 'Error starting OmniSharp server: none or multiple solutionfiles are found' ) def _StopServer( self ): """ Stop the OmniSharp server """ - if ( self._ServerIsRunning() ): - self._GetResponse( "/stopserver" ) + self._GetResponse( '/stopserver' ) def _ServerIsRunning( self ): """ Check if the OmniSharp server is running """ + self._StopServer() # temporal fix return False def _GetCompletions( self ): @@ -101,14 +109,16 @@ class CsharpCompleter( ThreadedCompleter ): parameters['buffer'] = '\n'.join( vim.current.buffer ) parameters['filename'] = vim.current.buffer.name - return self._GetResponse( '/autocomplete', parameters ) | [] + completions = self._GetResponse( '/autocomplete', parameters ) + return completions if completions != None else [] def _GetResponse( self, endPoint, parameters={} ): """ Handle communication with server """ - target = urlparse.urljoin( self.OmniSharp_host , endPoint ) + target = urlparse.urljoin( self.OmniSharpHost, endPoint ) parameters = urllib.urlencode( parameters ) try: response = urllib2.urlopen( target, parameters ) return json.loads( response.read() ) - except: + except Exception as e: + #vimsupport.PostVimMessage('OmniSharp : Could not connect to ' + target + ': ' + str(e)) return None