style fixes
This commit is contained in:
parent
a6a9fa10c3
commit
3617ce69db
@ -37,7 +37,8 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
|
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
super( CsharpCompleter, self ).__init__()
|
super( CsharpCompleter, self ).__init__()
|
||||||
self.OmniSharpPort = int( vimsupport.GetVariableValue( "g:ycm_csharp_server_port" ) )
|
self.OmniSharpPort = int( vimsupport.GetVariableValue(
|
||||||
|
"g:ycm_csharp_server_port" ) )
|
||||||
self.OmniSharpHost = 'http://localhost:' + str( self.OmniSharpPort )
|
self.OmniSharpHost = 'http://localhost:' + str( self.OmniSharpPort )
|
||||||
if vimsupport.GetBoolValue( "g:ycm_auto_start_csharp_server" ):
|
if vimsupport.GetBoolValue( "g:ycm_auto_start_csharp_server" ):
|
||||||
self._StartServer()
|
self._StartServer()
|
||||||
@ -79,23 +80,18 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
def _StartServer( self ):
|
def _StartServer( self ):
|
||||||
""" Start the OmniSharp server """
|
""" Start the OmniSharp server """
|
||||||
if not self._ServerIsRunning():
|
if not self._ServerIsRunning():
|
||||||
folder = os.path.dirname( vim.current.buffer.name )
|
solutionfiles = self._FindSolutionFiles()
|
||||||
solutionfiles = glob.glob1( folder, '*.sln' )
|
|
||||||
while not solutionfiles:
|
|
||||||
lastfolder = folder
|
|
||||||
folder = os.path.dirname( folder )
|
|
||||||
if folder == lastfolder:
|
|
||||||
break
|
|
||||||
solutionfiles = glob.glob1( folder, '*.sln' )
|
|
||||||
|
|
||||||
if len( solutionfiles ) == 0:
|
if len( solutionfiles ) == 0:
|
||||||
vimsupport.PostVimMessage( 'Error starting OmniSharp server: no solutionfile found' )
|
vimsupport.PostVimMessage(
|
||||||
|
'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( "Which solutionfile should be loaded?",
|
choice = vimsupport.PresentDialog(
|
||||||
[ str(i) + " " + s for i, s in enumerate( solutionfiles ) ] )
|
"Which solutionfile should be loaded?",
|
||||||
|
[ str(i) + " " + s for i, s in enumerate( solutionfiles ) ] )
|
||||||
if choice == -1:
|
if choice == -1:
|
||||||
vimsupport.PostVimMessage( 'OmniSharp not started' )
|
vimsupport.PostVimMessage( 'OmniSharp not started' )
|
||||||
return
|
return
|
||||||
@ -106,7 +102,8 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe' )
|
'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 ) + ' -s ' + solutionfile ]
|
command = [ omnisharp + ' -p ' + str( self.OmniSharpPort )
|
||||||
|
+ ' -s ' + 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 )
|
||||||
@ -119,6 +116,17 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
""" 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
|
||||||
|
|
||||||
def _GetCompletions( self ):
|
def _GetCompletions( self ):
|
||||||
""" Ask server for completions """
|
""" Ask server for completions """
|
||||||
line, column = vimsupport.CurrentLineAndColumn()
|
line, column = vimsupport.CurrentLineAndColumn()
|
||||||
@ -128,7 +136,7 @@ class CsharpCompleter( ThreadedCompleter ):
|
|||||||
parameters['buffer'] = '\n'.join( vim.current.buffer )
|
parameters['buffer'] = '\n'.join( vim.current.buffer )
|
||||||
parameters['filename'] = vim.current.buffer.name
|
parameters['filename'] = vim.current.buffer.name
|
||||||
|
|
||||||
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 ):
|
||||||
@ -140,5 +148,6 @@ 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 + ': ' + str(e))
|
vimsupport.PostVimMessage('OmniSharp : Could not connect to '
|
||||||
|
+ target + ': ' + str(e))
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user