def _StartServer( self ): with self._server_state_mutex: if self._ServerIsRunning(): return _logger.info( 'Starting Tern server...' ) self._server_port = utils.GetUnusedLocalhostPort() if _logger.isEnabledFor( logging.DEBUG ): extra_args = [ '--verbose' ] else: extra_args = [] command = [ PATH_TO_NODE, PATH_TO_TERN_BINARY, '--port', str( self._server_port ), '--host', SERVER_HOST, '--persistent', '--no-port-file' ] + extra_args _logger.debug( 'Starting tern with the following command: ' + ' '.join( command ) ) try: self._server_stdout = utils.CreateLogfile( LOGFILE_FORMAT.format( port = self._server_port, std = 'stdout' ) ) self._server_stderr = utils.CreateLogfile( LOGFILE_FORMAT.format( port = self._server_port, std = 'stderr' ) ) # We need to open a pipe to stdin or the Tern server is killed. # See https://github.com/ternjs/tern/issues/740#issuecomment-203979749 # For unknown reasons, this is only needed on Windows and for Python # 3.4+ on other platforms. with utils.OpenForStdHandle( self._server_stdout ) as stdout: with utils.OpenForStdHandle( self._server_stderr ) as stderr: self._server_handle = utils.SafePopen( command, stdin = PIPE, stdout = stdout, stderr = stderr ) except Exception: _logger.exception( 'Unable to start Tern server' ) self._CleanUp() if self._server_port and self._ServerIsRunning(): _logger.info( 'Tern Server started with pid: ' + str( self._server_handle.pid ) + ' listening on port ' + str( self._server_port ) ) _logger.info( 'Tern Server log files are: ' + self._server_stdout + ' and ' + self._server_stderr ) self._do_tern_project_check = True else: _logger.warning( 'Tern server did not start successfully' )
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_request = None 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 = ( "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, paths.PathToServerScript(), '--port={0}'.format( server_port ), '--options_file={0}'.format( options_file.name ), '--log={0}'.format( self._user_options[ 'log_level' ] ), '--idle_suicide_seconds={0}'.format( 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( '--stdout={0}'.format( self._server_stdout ) ) args.append( '--stderr={0}'.format( 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 )
def _ChooseOmnisharpPort(self): if not self._omnisharp_port: if self._desired_omnisharp_port: self._omnisharp_port = int(self._desired_omnisharp_port) else: self._omnisharp_port = utils.GetUnusedLocalhostPort() self._logger.info(u'using port {0}'.format(self._omnisharp_port))
def _StartServer(self): with self._server_lock: self._logger.info('Starting SSVIM server') self._http_port = utils.GetUnusedLocalhostPort() self._http_host = ToBytes('http://{0}:{1}'.format( SSVIM_IP, self._http_port)) self._logger.info('using port {0}'.format(self._http_port)) self._hmac_secret = self._GenerateHmacSecret() # The server will delete the secret_file after it's done reading it with NamedTemporaryFile(delete=False, mode='w+') as hmac_file: json.dump( {'hmac_secret': ToUnicode(b64encode(self._hmac_secret))}, hmac_file) command = [ PATH_TO_SSVIMHTTP, '--ip', SSVIM_IP, '--port', str(self._http_port), '--log', self._GetLoggingLevel(), '--hmac-file-secret', hmac_file.name ] self._logfile_stdout = utils.CreateLogfile( LOGFILE_FORMAT.format(port=self._http_port, std='stdout')) self._logfile_stderr = utils.CreateLogfile( LOGFILE_FORMAT.format(port=self._http_port, std='stderr')) with utils.OpenForStdHandle(self._logfile_stdout) as logout: with utils.OpenForStdHandle( self._logfile_stderr) as logerr: self._http_phandle = utils.SafePopen(command, stdout=logout, stderr=logerr) self._WaitForInitialSwiftySwiftVimBoot() self._logger.info('Started SSVIM server')
def _StartServer(self): """Start the Gocode server.""" with self._gocode_lock: _logger.info('Starting Gocode server') self._gocode_port = utils.GetUnusedLocalhostPort() self._gocode_address = '127.0.0.1:{0}'.format(self._gocode_port) command = [ self._gocode_binary_path, '-s', '-sock', 'tcp', '-addr', self._gocode_address ] if _logger.isEnabledFor(logging.DEBUG): command.append('-debug') self._gocode_stdout = LOG_FILENAME_FORMAT.format( port=self._gocode_port, std='stdout') self._gocode_stderr = LOG_FILENAME_FORMAT.format( port=self._gocode_port, std='stderr') with open(self._gocode_stdout, 'w') as stdout: with open(self._gocode_stderr, 'w') as stderr: self._gocode_handle = utils.SafePopen(command, stdout=stdout, stderr=stderr)
def _StartServer(self): with self._server_lock: self._logger.info('Starting JediHTTP server') self._jedihttp_port = utils.GetUnusedLocalhostPort() self._jedihttp_host = ToBytes('http://127.0.0.1:{0}'.format( self._jedihttp_port)) self._logger.info('using port {0}'.format(self._jedihttp_port)) self._hmac_secret = self._GenerateHmacSecret() # JediHTTP will delete the secret_file after it's done reading it with NamedTemporaryFile(delete=False, mode='w+') as hmac_file: json.dump( {'hmac_secret': ToUnicode(b64encode(self._hmac_secret))}, hmac_file) command = [ self._python_binary_path, PATH_TO_JEDIHTTP, '--port', str(self._jedihttp_port), '--log', self._GetLoggingLevel(), '--hmac-file-secret', hmac_file.name ] self._logfile_stdout = utils.CreateLogfile( LOGFILE_FORMAT.format(port=self._jedihttp_port, std='stdout')) self._logfile_stderr = utils.CreateLogfile( LOGFILE_FORMAT.format(port=self._jedihttp_port, std='stderr')) with utils.OpenForStdHandle(self._logfile_stdout) as logout: with utils.OpenForStdHandle(self._logfile_stderr) as logerr: self._jedihttp_phandle = utils.SafePopen(command, stdout=logout, stderr=logerr)
def _ChooseOmnisharpPort( self ): if not self._omnisharp_port: if self._desired_omnisharp_port: self._omnisharp_port = int( self._desired_omnisharp_port ) else: self._omnisharp_port = utils.GetUnusedLocalhostPort() LOGGER.info( 'using port %s', self._omnisharp_port )
def _StartServer(self): """Start the Gocode server.""" with self._gocode_lock: _logger.info('Starting Gocode server') self._gocode_port = utils.GetUnusedLocalhostPort() self._gocode_host = '127.0.0.1:{0}'.format(self._gocode_port) command = [ self._gocode_binary_path, '-s', '-sock', 'tcp', '-source', '-addr', self._gocode_host ] if _logger.isEnabledFor(logging.DEBUG): command.append('-debug') self._gocode_stdout = utils.CreateLogfile( LOGFILE_FORMAT.format(port=self._gocode_port, std='stdout')) self._gocode_stderr = utils.CreateLogfile( LOGFILE_FORMAT.format(port=self._gocode_port, std='stderr')) with utils.OpenForStdHandle(self._gocode_stdout) as stdout: with utils.OpenForStdHandle(self._gocode_stderr) as stderr: self._gocode_handle = utils.SafePopen(command, stdout=stdout, stderr=stderr)
def __init__(self, user_options, server_settings): self._name = server_settings['name'] self._supported_filetypes = server_settings['filetypes'] self._project_root_files = server_settings.get('project_root_files', []) self._capabilities = server_settings.get('capabilities', {}) self._command_line = server_settings.get('cmdline') self._port = server_settings.get('port') if self._port: connection_type = 'tcp' if self._port == '*': self._port = utils.GetUnusedLocalhostPort() else: connection_type = 'stdio' if self._command_line: self._command_line[0] = utils.FindExecutable(self._command_line[0]) for idx in range(len(self._command_line)): self._command_line[idx] = string.Template( self._command_line[idx]).safe_substitute( {'port': self._port}) super().__init__(user_options, connection_type)
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_request = None base.LoadJsonDefaultsIntoVim() user_options_store.SetAll(base.BuildServerConf()) self._user_options = user_options_store.GetAll() 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 this_file_path = os.path.dirname(os.path.realpath(__file__)) tabnine_binary_path = os.path.join(this_file_path, '../../binaries/') args = [ '--client=vim', '--port={0}'.format(server_port), '--options_file={0}'.format(options_file.name), '--log={0}'.format(self._user_options['log_level']), '--idle_suicide_seconds={0}'.format(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('--stdout={0}'.format(self._server_stdout)) args.append('--stderr={0}'.format(self._server_stderr)) if self._user_options['keep_logfiles']: args.append('--keep_logfiles') try: self._server_popen = start_tabnine_proc( cmd_args=args, binary_dir=tabnine_binary_path) except RuntimeError as error: error_message = str(error) self._logger.exception(error_message) vimsupport.PostVimMessage(error_message) return
def _StartServerNoLock(self): """Start the server, under the lock. Callers must hold self._server_state_mutex""" if self._ServerIsRunning(): return _logger.info('Starting Tern.js server...') self._server_port = utils.GetUnusedLocalhostPort() if _logger.isEnabledFor(logging.DEBUG): extra_args = ['--verbose'] else: extra_args = [] command = [ PATH_TO_NODE, PATH_TO_TERNJS_BINARY, '--port', str(self._server_port), '--host', SERVER_HOST, '--persistent', '--no-port-file' ] + extra_args _logger.debug('Starting tern with the following command: ' + ' '.join(command)) try: logfile_format = os.path.join(utils.PathToCreatedTempDir(), u'tern_{port}_{std}.log') self._server_stdout = logfile_format.format(port=self._server_port, std='stdout') self._server_stderr = logfile_format.format(port=self._server_port, std='stderr') # On Windows, we need to open a pipe to stdin to prevent Tern crashing # with following error: "Implement me. Unknown stdin file type!" with utils.OpenForStdHandle(self._server_stdout) as stdout: with utils.OpenForStdHandle(self._server_stderr) as stderr: self._server_handle = utils.SafePopen(command, stdin_windows=PIPE, stdout=stdout, stderr=stderr) except Exception: _logger.warning('Unable to start Tern.js server: ' + traceback.format_exc()) self._Reset() if self._server_port > 0 and self._ServerIsRunning(): _logger.info('Tern.js Server started with pid: ' + str(self._server_handle.pid) + ' listening on port ' + str(self._server_port)) _logger.info('Tern.js Server log files are: ' + self._server_stdout + ' and ' + self._server_stderr) self._do_tern_project_check = True else: _logger.warning('Tern.js server did not start successfully')
def _StartServer( self, request_data ): with self._server_state_mutex: if self._server_started: return self._server_started = True LOGGER.info( 'Starting Tern server...' ) self._SetServerProjectFileAndWorkingDirectory( request_data ) self._server_port = utils.GetUnusedLocalhostPort() command = [ PATH_TO_NODE, PATH_TO_TERN_BINARY, '--port', str( self._server_port ), '--host', SERVER_HOST, '--persistent', '--no-port-file' ] if LOGGER.isEnabledFor( logging.DEBUG ): command.append( '--verbose' ) LOGGER.debug( 'Starting tern with the following command: %s', command ) self._server_stdout = utils.CreateLogfile( LOGFILE_FORMAT.format( port = self._server_port, std = 'stdout' ) ) self._server_stderr = utils.CreateLogfile( LOGFILE_FORMAT.format( port = self._server_port, std = 'stderr' ) ) # We need to open a pipe to stdin or the Tern server is killed. # See https://github.com/ternjs/tern/issues/740#issuecomment-203979749 # For unknown reasons, this is only needed on Windows and for Python # 3.4+ on other platforms. with utils.OpenForStdHandle( self._server_stdout ) as stdout: with utils.OpenForStdHandle( self._server_stderr ) as stderr: self._server_handle = utils.SafePopen( command, stdin = PIPE, stdout = stdout, stderr = stderr, cwd = self._server_working_dir ) if self._ServerIsRunning(): LOGGER.info( 'Tern Server started with pid %d listening on port %d', self._server_handle.pid, self._server_port ) LOGGER.info( 'Tern Server log files are %s and %s', self._server_stdout, self._server_stderr ) self._do_tern_project_check = True else: LOGGER.warning( 'Tern server did not start successfully' )
def _StartServer(self, request_data): """ Start the OmniSharp server """ self._logger.info('startup') #Note: detection could throw an exception if an extra_conf_store needs to be confirmed path_to_solutionfile = solutiondetection.FindSolutionPath( request_data['filepath']) if not path_to_solutionfile: raise RuntimeError('Autodetection of solution file failed.\n') self._logger.info( 'Loading solution file {0}'.format(path_to_solutionfile)) self._omnisharp_port = utils.GetUnusedLocalhostPort() # we need to pass the command to Popen as a string since we're passing # shell=True (as recommended by Python's doc) command = ' '.join([ PATH_TO_OMNISHARP_BINARY, '-p', str(self._omnisharp_port), '-s', '"{0}"'.format(path_to_solutionfile) ]) if not utils.OnWindows() and not utils.OnCygwin(): command = 'mono ' + command if utils.OnCygwin(): command = command + ' --client-path-mode Cygwin' filename_format = os.path.join(utils.PathToTempDir(), 'omnisharp_{port}_{sln}_{std}.log') solutionfile = os.path.basename(path_to_solutionfile) self._filename_stdout = filename_format.format( port=self._omnisharp_port, sln=solutionfile, std='stdout') self._filename_stderr = filename_format.format( port=self._omnisharp_port, sln=solutionfile, std='stderr') with open(self._filename_stderr, 'w') as fstderr: with open(self._filename_stdout, 'w') as fstdout: # shell=True is needed for Windows so OmniSharp does not spawn # in a new visible window self._omnisharp_phandle = utils.SafePopen(command, stdout=fstdout, stderr=fstderr, shell=True) self._solution_path = path_to_solutionfile self._logger.info('Starting OmniSharp server')
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 server_port = utils.GetUnusedLocalhostPort() # The temp options file is deleted by ycmd during startup 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) options_file.flush() args = [ paths.PathToPythonInterpreter(), paths.PathToServerScript(), '--port={0}'.format(server_port), '--options_file={0}'.format(options_file.name), '--log={0}'.format(self._user_options['log_level']), '--idle_suicide_seconds={0}'.format( 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('--stdout={0}'.format(self._server_stdout)) args.append('--stderr={0}'.format(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) BaseRequest.server_location = 'http://127.0.0.1:' + str( server_port) BaseRequest.hmac_secret = hmac_secret self._NotifyUserIfServerCrashed()
def _SetupServer(self): self._available_completers = {} server_port = utils.GetUnusedLocalhostPort() # The temp options file is deleted by ycmd during startup with tempfile.NamedTemporaryFile(delete=False) as options_file: hmac_secret = os.urandom(HMAC_SECRET_LENGTH) options_dict = dict(self._user_options) options_dict['hmac_secret'] = base64.b64encode(hmac_secret) json.dump(options_dict, options_file) options_file.flush() args = [ utils.PathToPythonInterpreter(), _PathToServerScript(), '--port={0}'.format(server_port), '--options_file={0}'.format(options_file.name), '--log={0}'.format(self._user_options['server_log_level']), '--idle_suicide_seconds={0}'.format( SERVER_IDLE_SUICIDE_SECONDS) ] if not self._user_options['server_use_vim_stdout']: filename_format = os.path.join(utils.PathToTempDir(), 'server_{port}_{std}.log') self._server_stdout = filename_format.format(port=server_port, std='stdout') self._server_stderr = filename_format.format(port=server_port, std='stderr') args.append('--stdout={0}'.format(self._server_stdout)) args.append('--stderr={0}'.format(self._server_stderr)) if self._user_options['server_keep_logfiles']: args.append('--keep_logfiles') self._server_popen = utils.SafePopen(args, stdin_windows=PIPE, stdout=PIPE, stderr=PIPE) BaseRequest.server_location = 'http://127.0.0.1:' + str( server_port) BaseRequest.hmac_secret = hmac_secret self._NotifyUserIfServerCrashed()
def _StartServer(self): """ Start racerd. """ with self._server_state_lock: self._hmac_secret = self._CreateHmacSecret() secret_file_path = self._WriteSecretFile(self._hmac_secret) port = utils.GetUnusedLocalhostPort() args = [ self._racerd, 'serve', '--port', str(port), '-l', '--secret-file', secret_file_path ] # Enable logging of crashes env = os.environ.copy() env['RUST_BACKTRACE'] = '1' if self._rust_source_path: args.extend(['--rust-src-path', self._rust_source_path]) filename_format = p.join(utils.PathToTempDir(), 'racerd_{port}_{std}.log') self._server_stdout = filename_format.format(port=port, std='stdout') self._server_stderr = filename_format.format(port=port, std='stderr') with open(self._server_stderr, 'w') as fstderr: with open(self._server_stdout, 'w') as fstdout: self._racerd_phandle = utils.SafePopen(args, stdout=fstdout, stderr=fstderr, env=env) self._racerd_host = 'http://127.0.0.1:{0}'.format(port) _logger.info('RustCompleter using host = ' + self._racerd_host)
def _StartServer(self): with self._server_state_lock: port = utils.GetUnusedLocalhostPort() self._hmac_secret = self._CreateHmacSecret() # racerd will delete the secret_file after it's done reading it with tempfile.NamedTemporaryFile(delete=False) as secret_file: secret_file.write(self._hmac_secret) args = [ self._racerd, 'serve', '--port', str(port), '-l', '--secret-file', secret_file.name ] # Enable logging of crashes env = os.environ.copy() SetEnviron(env, 'RUST_BACKTRACE', '1') if self._rust_source_path: args.extend(['--rust-src-path', self._rust_source_path]) filename_format = p.join(utils.PathToCreatedTempDir(), 'racerd_{port}_{std}.log') self._server_stdout = filename_format.format(port=port, std='stdout') self._server_stderr = filename_format.format(port=port, std='stderr') with utils.OpenForStdHandle(self._server_stderr) as fstderr: with utils.OpenForStdHandle(self._server_stdout) as fstdout: self._racerd_phandle = utils.SafePopen(args, stdout=fstdout, stderr=fstderr, env=env) self._racerd_host = 'http://127.0.0.1:{0}'.format(port) if not self.ServerIsRunning(): raise RuntimeError('Failed to start racerd!') _logger.info('Racerd started on: ' + self._racerd_host)
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._default_options) 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') if 'YCM_WITH_PTVSD' in os.environ: args[1:1] = [ '-m', 'ptvsd', '--host', 'localhost', '--port', '1234', '--wait', '--no-subprocesses' ] self._logger.debug('Starting ycmd with: %s', args) self._server_popen = utils.SafePopen(args, stdin_windows=PIPE, stdout=PIPE, stderr=PIPE)
def _StartServerNoLock(self): """Start the server, under the lock. Callers must hold self._server_state_mutex""" if self._ServerIsRunning(): return _logger.info('Starting Tern.js server...') self._server_port = utils.GetUnusedLocalhostPort() if _logger.isEnabledFor(logging.DEBUG): extra_args = ['--verbose'] else: extra_args = [] command = [ PATH_TO_NODE, PATH_TO_TERNJS_BINARY, '--port', str(self._server_port), '--host', SERVER_HOST, '--persistent', '--no-port-file' ] + extra_args _logger.debug('Starting tern with the following command: ' + ' '.join(command)) try: if utils.OnWindows(): # FIXME: # For unknown reasons, redirecting stdout and stderr on windows for this # particular Completer does not work. It causes tern to crash with an # access error on startup. Rather than spending too much time trying to # understand this (it's either a bug in Python, node or our code, and it # isn't obvious which), we just suppress the log files on this platform. # ATOW the only output from the server is the line saying it is # listening anyway. Verbose logging includes requests and responses, but # they can be tested on other platforms. self._server_stdout = "<Not supported on this platform>" self._server_stderr = "<Not supported on this platform>" self._server_handle = utils.SafePopen(command) else: logfile_format = os.path.join(utils.PathToTempDir(), u'tern_{port}_{std}.log') self._server_stdout = logfile_format.format( port=self._server_port, std='stdout') self._server_stderr = logfile_format.format( port=self._server_port, std='stderr') with open(self._server_stdout, 'w') as stdout: with open(self._server_stderr, 'w') as stderr: self._server_handle = utils.SafePopen(command, stdout=stdout, stderr=stderr) except Exception: _logger.warning('Unable to start Tern.js server: ' + traceback.format_exc()) self._Reset() if self._server_port > 0 and self._ServerIsRunning(): _logger.info('Tern.js Server started with pid: ' + str(self._server_handle.pid) + ' listening on port ' + str(self._server_port)) _logger.info('Tern.js Server log files are: ' + self._server_stdout + ' and ' + self._server_stderr) self._do_tern_project_check = True else: _logger.warning('Tern.js server did not start successfully')
def _ChoosePort(self): if not self._jedihttp_port: self._jedihttp_port = utils.GetUnusedLocalhostPort() self._logger.info(u'using port {0}'.format(self._jedihttp_port))
TCPSingleStreamConnection, ResponseFailedException) from ycmd import handlers, utils from ycmd.tests.language_server import IsolatedYcmd, PathToTestFile from ycmd.tests.test_utils import (BuildRequest, CompletionEntryMatcher, ErrorMatcher, LocationMatcher, RangeMatcher, SignatureAvailableMatcher, WaitUntilCompleterServerReady) from ycmd.utils import ReadFile DIR_OF_THIS_SCRIPT = p.dirname(p.abspath(__file__)) PATH_TO_GENERIC_COMPLETER = p.join(DIR_OF_THIS_SCRIPT, '..', '..', '..', 'third_party', 'generic_server', 'server', 'out', 'server.js') TEST_FILE = PathToTestFile('generic_server', 'test_file') TEST_FILE_CONTENT = ReadFile(TEST_FILE) TEST_PORT = utils.GetUnusedLocalhostPort() @IsolatedYcmd({ 'language_server': [{ 'name': 'foo', 'filetypes': ['foo'], 'cmdline': ['node', PATH_TO_GENERIC_COMPLETER, '--stdio'] }] }) def GenericLSPCompleter_GetCompletions_NotACompletionProvider_test(app): completer = handlers._server_state.GetFiletypeCompleter(['foo']) with patch.object(completer, '_is_completion_provider', False): request = BuildRequest(filepath=TEST_FILE, filetype='foo',
def _StartServerNoLock(self): """Start the server, under the lock. Callers must hold self._server_state_mutex""" if self._ServerIsRunning(): return _logger.info('Starting Tern.js server...') self._server_port = utils.GetUnusedLocalhostPort() if _logger.isEnabledFor(logging.DEBUG): extra_args = ['--verbose'] else: extra_args = [] command = [ PATH_TO_NODE, PATH_TO_TERNJS_BINARY, '--port', str(self._server_port), '--host', SERVER_HOST, '--persistent', '--no-port-file' ] + extra_args _logger.debug('Starting tern with the following command: ' + ' '.join(command)) try: logfile_format = os.path.join(utils.PathToCreatedTempDir(), u'tern_{port}_{std}.log') self._server_stdout = logfile_format.format(port=self._server_port, std='stdout') self._server_stderr = logfile_format.format(port=self._server_port, std='stderr') # We need to open a pipe to stdin or the Tern server is killed. # See https://github.com/ternjs/tern/issues/740#issuecomment-203979749 # For unknown reasons, this is only needed on Windows and for Python 3.4+ # on other platforms. with utils.OpenForStdHandle(self._server_stdout) as stdout: with utils.OpenForStdHandle(self._server_stderr) as stderr: self._server_handle = utils.SafePopen(command, stdin=PIPE, stdout=stdout, stderr=stderr) except Exception: _logger.warning('Unable to start Tern.js server: ' + traceback.format_exc()) self._Reset() if self._server_port > 0 and self._ServerIsRunning(): _logger.info('Tern.js Server started with pid: ' + str(self._server_handle.pid) + ' listening on port ' + str(self._server_port)) _logger.info('Tern.js Server log files are: ' + self._server_stdout + ' and ' + self._server_stderr) self._do_tern_project_check = True else: _logger.warning('Tern.js server did not start successfully')
def _StartServer( self, request_data ): """ Start the OmniSharp server """ self._logger.info( 'startup' ) self._omnisharp_port = utils.GetUnusedLocalhostPort() solution_files, folder = _FindSolutionFiles( request_data[ 'filepath' ] ) if len( solution_files ) == 0: raise RuntimeError( 'Error starting OmniSharp server: no solutionfile found' ) elif len( solution_files ) == 1: solutionfile = solution_files[ 0 ] else: # multiple solutions found : if there is one whose name is the same # as the folder containing the file we edit, use this one # (e.g. if we have bla/Project.sln and we are editing # bla/Project/Folder/File.cs, use bla/Project.sln) filepath_components = _PathComponents( request_data[ 'filepath' ] ) solutionpath = _PathComponents( folder ) foldername = '' if len( filepath_components ) > len( solutionpath ): foldername = filepath_components[ len( solutionpath ) ] solution_file_candidates = [ sfile for sfile in solution_files if _GetFilenameWithoutExtension( sfile ) == foldername ] if len( solution_file_candidates ) == 1: solutionfile = solution_file_candidates[ 0 ] else: raise RuntimeError( 'Found multiple solution files instead of one!\n{0}'.format( solution_files ) ) path_to_solutionfile = os.path.join( folder, solutionfile ) # we need to pass the command to Popen as a string since we're passing # shell=True (as recommended by Python's doc) command = ' '.join( [ PATH_TO_OMNISHARP_BINARY, '-p', str( self._omnisharp_port ), '-s', path_to_solutionfile ] ) if not utils.OnWindows() and not utils.OnCygwin(): command = 'mono ' + command if utils.OnCygwin(): command = command + ' --client-path-mode Cygwin' filename_format = os.path.join( utils.PathToTempDir(), 'omnisharp_{port}_{sln}_{std}.log' ) self._filename_stdout = filename_format.format( port=self._omnisharp_port, sln=solutionfile, std='stdout' ) self._filename_stderr = filename_format.format( port=self._omnisharp_port, sln=solutionfile, std='stderr' ) with open( self._filename_stderr, 'w' ) as fstderr: with open( self._filename_stdout, 'w' ) as fstdout: # shell=True is needed for Windows so OmniSharp does not spawn # in a new visible window utils.SafePopen( command, stdout=fstdout, stderr=fstderr, shell=True ) self._logger.info( 'Starting OmniSharp server' )
def _ChooseOmnisharpPort( self ): self._omnisharp_port = int( self.user_options.get( 'csharp_server_port', 0 ) ) if not self._omnisharp_port: self._omnisharp_port = utils.GetUnusedLocalhostPort() self._logger.info( u'using port {0}'.format( self._omnisharp_port ) )