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( u'Loading solution file {0}'.format(path_to_solutionfile)) self._ChooseOmnisharpPort() # 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', u'"{0}"'.format(path_to_solutionfile) ]) if not utils.OnWindows() and not utils.OnCygwin(): command = u'mono ' + command if utils.OnCygwin(): command = command + ' --client-path-mode Cygwin' filename_format = os.path.join(utils.PathToTempDir(), u'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 _StartServer(self): """ Start the OmniSharp server if not already running. Use a lock to avoid starting the server multiple times for the same solution. """ with self._server_state_lock: if self.ServerIsRunning(): return self._logger.info('Starting OmniSharp server') path_to_solutionfile = self._solution_path self._logger.info( u'Loading solution file {0}'.format(path_to_solutionfile)) self._ChooseOmnisharpPort() command = [ PATH_TO_OMNISHARP_BINARY, '-p', str(self._omnisharp_port), '-s', u'{0}'.format(path_to_solutionfile) ] if not utils.OnWindows() and not utils.OnCygwin(): command.insert(0, 'mono') if utils.OnCygwin(): command.extend(['--client-path-mode', 'Cygwin']) filename_format = os.path.join( utils.PathToTempDir(), u'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: self._omnisharp_phandle = utils.SafePopen(command, stdout=fstdout, stderr=fstderr) self._external_omnisharp = False self._solution_path = path_to_solutionfile
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 the OmniSharp server """ self._logger.info('startup') path_to_solutionfile = self._solution_path self._logger.info( u'Loading solution file {0}'.format(path_to_solutionfile)) self._ChooseOmnisharpPort() command = [ PATH_TO_OMNISHARP_BINARY, '-p', str(self._omnisharp_port), '-s', u'{0}'.format(path_to_solutionfile) ] if not utils.OnWindows() and not utils.OnCygwin(): command.insert(0, 'mono') if utils.OnCygwin(): command.extend(['--client-path-mode', 'Cygwin']) filename_format = os.path.join(utils.PathToTempDir(), u'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: self._omnisharp_phandle = utils.SafePopen(command, stdout=fstdout, stderr=fstderr) self._solution_path = path_to_solutionfile self._logger.info('Starting OmniSharp server')
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)
from ycmd.utils import ToUtf8IfNeeded from ycmd.completers.completer import Completer from ycmd import responses, utils from jedihttp import hmaclib import logging import urlparse import requests import threading import sys import os import base64 HMAC_SECRET_LENGTH = 16 PYTHON_EXECUTABLE_PATH = sys.executable LOG_FILENAME_FORMAT = os.path.join(utils.PathToTempDir(), u'jedihttp_{port}_{std}.log') PATH_TO_JEDIHTTP = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', '..', '..', 'third_party', 'JediHTTP', 'jedihttp.py') class HmacAuth(requests.auth.AuthBase): def __init__(self, secret): self._hmac_helper = hmaclib.JediHTTPHmacHelper(secret) def __call__(self, req): self._hmac_helper.SignRequestHeaders(req.headers, req.method, req.path_url, req.body) return req
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 _LogFileName(): with NamedTemporaryFile(dir=utils.PathToTempDir(), prefix='tsserver_', suffix='.log', delete=False) as logfile: return logfile.name
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' )