Find a free port for OmniSharp if another OmniSharp is using the default port

This commit is contained in:
Spencer G. Jones 2013-07-15 09:12:32 -06:00
parent e15ec6ee93
commit 1a7da1650c
2 changed files with 17 additions and 1 deletions

View File

@ -163,6 +163,8 @@ let g:ycm_csharp_server_stderr_logfile_format =
let g:ycm_csharp_server_stdout_logfile_format =
\ get( g:, 'ycm_csharp_server_stdout_logfile_format', '' )
let g:ycm_find_free_port_for_csharp_server =
\ get( g:, 'ycm_find_free_port_for_csharp_server', 0 )
" On-demand loading. Let's use the autoload folder and not slow down vim's
" startup procedure.

View File

@ -38,7 +38,13 @@ class CsharpCompleter( ThreadedCompleter ):
def __init__( self ):
super( CsharpCompleter, self ).__init__()
self.OmniSharpPort = int( vimsupport.GetVariableValue( "g:ycm_csharp_server_port" ) )
self.OmniSharpHost = 'http://localhost:' + str( self.OmniSharpPort )
self.OmniSharpHost = ''
if vimsupport.GetBoolValue( "g:ycm_find_free_port_for_csharp_server" ):
self._FindFreePort();
self._RefreshOmniSharpHost()
if vimsupport.GetBoolValue( "g:ycm_auto_start_csharp_server" ):
self._StartServer()
@ -132,6 +138,14 @@ class CsharpCompleter( ThreadedCompleter ):
""" Check if the OmniSharp server is running """
return self._GetResponse( '/checkalivestatus', silent=True ) != None
def _FindFreePort( self ):
while self._ServerIsRunning():
self.OmniSharpPort = self.OmniSharpPort + 1
self._RefreshOmniSharpHost()
def _RefreshOmniSharpHost ( self ):
self.OmniSharpHost = 'http://localhost:' + str( self.OmniSharpPort )
def _GetCompletions( self ):
""" Ask server for completions """
line, column = vimsupport.CurrentLineAndColumn()