示例#1
0
 def __init__(self):
     self._available_completers = {}
     self._user_options = None
     self._user_notified_about_crash = False
     self._omnicomp = None
     self._buffers = None
     self._latest_completion_request = None
     self._latest_signature_help_request = None
     self._signature_help_available_requests = SigHelpAvailableByFileType()
     self._signature_help_state = signature_help.SignatureHelpState()
     self._logger = logging.getLogger('ycm')
     self._client_logfile = None
     self._server_stdout = None
     self._server_stderr = None
     self._server_popen = None
     self._filetypes_with_keywords_loaded = set()
     self._ycmd_keepalive = YcmdKeepalive()
     self._server_is_ready_with_cache = False
     self._SetUpLogging()
     self._SetUpServer()
     self._ycmd_keepalive.Start()
示例#2
0
  def _SetUpServer( self ):
    self._available_completers = {}
    self._user_notified_about_crash = False
    self._filetypes_with_keywords_loaded = set()
    self._server_is_ready_with_cache = False
    self._message_poll_requests = {}

    self._latest_completion_request = None
    self._latest_signature_help_request = None
    self._signature_help_available_requests = SigHelpAvailableByFileType()
    self._latest_command_reqeust = None

    self._signature_help_state = signature_help.SignatureHelpState()
    self._user_options = base.GetUserOptions()
    self._omnicomp = OmniCompleter( self._user_options )
    self._buffers = BufferDict( self._user_options )

    self._SetLogLevel()

    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' ]

    # The temp options file is deleted by ycmd during startup.
    with NamedTemporaryFile( delete = False, mode = 'w+' ) as options_file:
      json.dump( options_dict, options_file )

    server_port = utils.GetUnusedLocalhostPort()

    BaseRequest.server_location = 'http://127.0.0.1:' + str( server_port )
    BaseRequest.hmac_secret = hmac_secret

    try:
      python_interpreter = paths.PathToPythonInterpreter()
    except RuntimeError as error:
      error_message = (
        f"Unable to start the ycmd server. { str( error ).rstrip( '.' ) }. "
        "Correct the error then restart the server "
        "with ':YcmRestartServer'." )
      self._logger.exception( error_message )
      vimsupport.PostVimMessage( error_message )
      return

    args = [ python_interpreter,
             paths.PathToServerScript(),
             f'--port={ server_port }',
             f'--options_file={ options_file.name }',
             f'--log={ self._user_options[ "log_level" ] }',
             f'--idle_suicide_seconds={ SERVER_IDLE_SUICIDE_SECONDS }' ]

    self._server_stdout = utils.CreateLogfile(
        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( f'--stdout={ self._server_stdout }' )
    args.append( f'--stderr={ self._server_stderr }' )

    if self._user_options[ 'keep_logfiles' ]:
      args.append( '--keep_logfiles' )

    self._server_popen = utils.SafePopen( args, stdin_windows = PIPE,
                                          stdout = PIPE, stderr = PIPE )