From 1a7da1650c3763c5c49fab0ba91a20eb59873357 Mon Sep 17 00:00:00 2001 From: "Spencer G. Jones" Date: Mon, 15 Jul 2013 09:12:32 -0600 Subject: [PATCH] Find a free port for OmniSharp if another OmniSharp is using the default port --- plugin/youcompleteme.vim | 2 ++ python/ycm/completers/cs/cs_completer.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index 2e9efff3..9787f52f 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -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. diff --git a/python/ycm/completers/cs/cs_completer.py b/python/ycm/completers/cs/cs_completer.py index 280c868d..77db628c 100755 --- a/python/ycm/completers/cs/cs_completer.py +++ b/python/ycm/completers/cs/cs_completer.py @@ -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()