Auto merge of #2788 - micbou:options-file, r=bstaletic

[READY] Close options file before starting server

See PR https://github.com/Valloric/ycmd/pull/841.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2788)
<!-- Reviewable:end -->
This commit is contained in:
zzbot 2017-09-23 15:07:41 -07:00 committed by GitHub
commit 32f1eae9cb

View File

@ -138,52 +138,53 @@ class YouCompleteMe( object ):
self._filetypes_with_keywords_loaded = set() self._filetypes_with_keywords_loaded = set()
self._server_is_ready_with_cache = False self._server_is_ready_with_cache = False
server_port = utils.GetUnusedLocalhostPort() hmac_secret = os.urandom( HMAC_SECRET_LENGTH )
# The temp options file is deleted by ycmd during startup options_dict = dict( self._user_options )
options_dict[ 'hmac_secret' ] = utils.ToUnicode(
base64.b64encode( hmac_secret ) )
options_dict[ 'server_keep_logfiles' ] = self._user_options[
'keep_logfiles' ]
# The temp options file is deleted by ycmd during startup.
with NamedTemporaryFile( delete = False, mode = 'w+' ) as options_file: with NamedTemporaryFile( delete = False, mode = 'w+' ) as options_file:
hmac_secret = os.urandom( HMAC_SECRET_LENGTH )
options_dict = dict( self._user_options )
options_dict[ 'hmac_secret' ] = utils.ToUnicode(
base64.b64encode( hmac_secret ) )
options_dict[ 'server_keep_logfiles' ] = self._user_options[
'keep_logfiles' ]
json.dump( options_dict, options_file ) json.dump( options_dict, options_file )
options_file.flush()
BaseRequest.server_location = 'http://127.0.0.1:' + str( server_port ) server_port = utils.GetUnusedLocalhostPort()
BaseRequest.hmac_secret = hmac_secret
try: BaseRequest.server_location = 'http://127.0.0.1:' + str( server_port )
python_interpreter = paths.PathToPythonInterpreter() BaseRequest.hmac_secret = hmac_secret
except RuntimeError as error:
error_message = (
"Unable to start the ycmd server. {0}. "
"Correct the error then restart the server "
"with ':YcmRestartServer'.".format( str( error ).rstrip( '.' ) ) )
self._logger.exception( error_message )
vimsupport.PostVimMessage( error_message )
return
args = [ python_interpreter, try:
paths.PathToServerScript(), python_interpreter = paths.PathToPythonInterpreter()
'--port={0}'.format( server_port ), except RuntimeError as error:
'--options_file={0}'.format( options_file.name ), error_message = (
'--log={0}'.format( self._user_options[ 'log_level' ] ), "Unable to start the ycmd server. {0}. "
'--idle_suicide_seconds={0}'.format( "Correct the error then restart the server "
SERVER_IDLE_SUICIDE_SECONDS ) ] "with ':YcmRestartServer'.".format( str( error ).rstrip( '.' ) ) )
self._logger.exception( error_message )
vimsupport.PostVimMessage( error_message )
return
self._server_stdout = utils.CreateLogfile( args = [ python_interpreter,
SERVER_LOGFILE_FORMAT.format( port = server_port, std = 'stdout' ) ) paths.PathToServerScript(),
self._server_stderr = utils.CreateLogfile( '--port={0}'.format( server_port ),
SERVER_LOGFILE_FORMAT.format( port = server_port, std = 'stderr' ) ) '--options_file={0}'.format( options_file.name ),
args.append( '--stdout={0}'.format( self._server_stdout ) ) '--log={0}'.format( self._user_options[ 'log_level' ] ),
args.append( '--stderr={0}'.format( self._server_stderr ) ) '--idle_suicide_seconds={0}'.format(
SERVER_IDLE_SUICIDE_SECONDS ) ]
if self._user_options[ 'keep_logfiles' ]: self._server_stdout = utils.CreateLogfile(
args.append( '--keep_logfiles' ) SERVER_LOGFILE_FORMAT.format( port = server_port, std = 'stdout' ) )
self._server_stderr = utils.CreateLogfile(
SERVER_LOGFILE_FORMAT.format( port = server_port, std = 'stderr' ) )
args.append( '--stdout={0}'.format( self._server_stdout ) )
args.append( '--stderr={0}'.format( self._server_stderr ) )
self._server_popen = utils.SafePopen( args, stdin_windows = PIPE, if self._user_options[ 'keep_logfiles' ]:
stdout = PIPE, stderr = PIPE ) args.append( '--keep_logfiles' )
self._server_popen = utils.SafePopen( args, stdin_windows = PIPE,
stdout = PIPE, stderr = PIPE )
self._NotifyUserIfServerCrashed() self._NotifyUserIfServerCrashed()