Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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')
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
  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' )
Exemplo n.º 5
0
    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')
Exemplo n.º 6
0
  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' )
Exemplo n.º 7
0
    def StartServer(self, request_data):
        with self._server_state_mutex:
            if self.ServerIsHealthy():
                return

            # Ensure we cleanup all states.
            self._Reset()

            LOGGER.info('Starting clangd: %s', self._clangd_command)
            self._stderr_file = utils.CreateLogfile('clangd_stderr')
            with utils.OpenForStdHandle(self._stderr_file) as stderr:
                self._server_handle = utils.SafePopen(self._clangd_command,
                                                      stdin=subprocess.PIPE,
                                                      stdout=subprocess.PIPE,
                                                      stderr=stderr)

            self._connection = (
                language_server_completer.StandardIOLanguageServerConnection(
                    self._server_handle.stdin, self._server_handle.stdout,
                    self.GetDefaultNotificationHandler()))

            self._connection.Start()

            try:
                self._connection.AwaitServerConnection()
            except language_server_completer.LanguageServerConnectionTimeout:
                LOGGER.error('clangd failed to start, or did not connect '
                             'successfully')
                self.Shutdown()
                return

        LOGGER.info('clangd started')

        self.SendInitialize(request_data)
Exemplo n.º 8
0
def OpenForStdHandle_PrintDoesntThrowException_test():
    try:
        temp = PathToTestFile('open-for-std-handle')
        with utils.OpenForStdHandle(temp) as f:
            print('foo', file=f)
    finally:
        os.remove(temp)
Exemplo n.º 9
0
    def StartServer(self, request_data):
        with self._server_state_mutex:
            LOGGER.info('Starting %s: %s', self.GetServerName(),
                        self.GetCommandLine())

            self._stderr_file = utils.CreateLogfile('{}_stderr'.format(
                utils.MakeSafeFileNameString(self.GetServerName())))

            with utils.OpenForStdHandle(self._stderr_file) as stderr:
                self._server_handle = utils.SafePopen(self.GetCommandLine(),
                                                      stdin=subprocess.PIPE,
                                                      stdout=subprocess.PIPE,
                                                      stderr=stderr)

            self._connection = (lsc.StandardIOLanguageServerConnection(
                self._server_handle.stdin, self._server_handle.stdout,
                self.GetDefaultNotificationHandler()))

            self._connection.Start()

            try:
                self._connection.AwaitServerConnection()
            except lsc.LanguageServerConnectionTimeout:
                LOGGER.error(
                    '%s failed to start, or did not connect successfully',
                    self.GetServerName())
                self.Shutdown()
                return False

        LOGGER.info('%s started', self.GetServerName())

        return True
Exemplo n.º 10
0
    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

            LOGGER.info('Starting OmniSharp server')
            LOGGER.info('Loading solution file %s', self._solution_path)

            self._ChooseOmnisharpPort()

            # Roslyn fails unless you open it in shell in Window on Python 2
            # Shell isn't preferred, but I don't see any other way to resolve
            shell_required = PY2 and utils.OnWindows()

            command = [
                PATH_TO_ROSLYN_OMNISHARP_BINARY, '-p',
                str(self._omnisharp_port), '-s',
                str(self._solution_path)
            ]

            if (not utils.OnWindows()
                    and PATH_TO_ROSLYN_OMNISHARP_BINARY.endswith('.exe')):
                command.insert(0, 'mono')

            LOGGER.info('Starting OmniSharp server with: %s', command)

            solutionfile = os.path.basename(self._solution_path)
            self._filename_stdout = utils.CreateLogfile(
                LOGFILE_FORMAT.format(port=self._omnisharp_port,
                                      sln=solutionfile,
                                      std='stdout'))
            self._filename_stderr = utils.CreateLogfile(
                LOGFILE_FORMAT.format(port=self._omnisharp_port,
                                      sln=solutionfile,
                                      std='stderr'))

            with utils.OpenForStdHandle(self._filename_stderr) as fstderr:
                with utils.OpenForStdHandle(self._filename_stdout) as fstdout:
                    self._omnisharp_phandle = utils.SafePopen(
                        command,
                        stdout=fstdout,
                        stderr=fstderr,
                        shell=shell_required)

            LOGGER.info('Started OmniSharp server')
Exemplo n.º 11
0
    def _StartServer(self, request_data):
        with self._server_state_mutex:
            if self._server_started:
                return

            self._server_started = True

            _logger.info('Starting jdt.ls Language Server...')

            self._project_dir = _FindProjectDir(
                os.path.dirname(request_data['filepath']))
            self._workspace_path = _WorkspaceDirForProject(
                self._project_dir, self._use_clean_workspace)

            command = [
                PATH_TO_JAVA,
                '-Dfile.encoding=UTF-8',
                '-Declipse.application=org.eclipse.jdt.ls.core.id1',
                '-Dosgi.bundles.defaultStartLevel=4',
                '-Declipse.product=org.eclipse.jdt.ls.core.product',
                '-Dlog.level=ALL',
                '-jar',
                self._launcher_path,
                '-configuration',
                self._launcher_config,
                '-data',
                self._workspace_path,
            ]

            _logger.debug('Starting java-server with the following command: '
                          '{0}'.format(' '.join(command)))

            self._server_stderr = utils.CreateLogfile('jdt.ls_stderr_')
            with utils.OpenForStdHandle(self._server_stderr) as stderr:
                self._server_handle = utils.SafePopen(command,
                                                      stdin=PIPE,
                                                      stdout=PIPE,
                                                      stderr=stderr)

            self._connection = (
                language_server_completer.StandardIOLanguageServerConnection(
                    self._server_handle.stdin, self._server_handle.stdout,
                    self.GetDefaultNotificationHandler()))

            self._connection.Start()

            try:
                self._connection.AwaitServerConnection()
            except language_server_completer.LanguageServerConnectionTimeout:
                _logger.error('jdt.ls failed to start, or did not connect '
                              'successfully')
                self._StopServer()
                return

        _logger.info('jdt.ls Language Server started')

        self.SendInitialize(request_data)
Exemplo n.º 12
0
    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'])

            solutionfile = os.path.basename(path_to_solutionfile)
            self._filename_stdout = utils.CreateLogfile(
                LOGFILE_FORMAT.format(port=self._omnisharp_port,
                                      sln=solutionfile,
                                      std='stdout'))
            self._filename_stderr = utils.CreateLogfile(
                LOGFILE_FORMAT.format(port=self._omnisharp_port,
                                      sln=solutionfile,
                                      std='stderr'))

            with utils.OpenForStdHandle(self._filename_stderr) as fstderr:
                with utils.OpenForStdHandle(self._filename_stdout) as fstdout:
                    self._omnisharp_phandle = utils.SafePopen(command,
                                                              stdout=fstdout,
                                                              stderr=fstderr)

            self._solution_path = path_to_solutionfile
Exemplo n.º 13
0
    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

            LOGGER.info('Starting OmniSharp server')
            LOGGER.info('Loading solution file %s', self._solution_path)

            self._ChooseOmnisharpPort()

            command = [
                PATH_TO_OMNISHARP_ROSLYN_BINARY, '-p',
                str(self._omnisharp_port), '-s',
                str(self._solution_path)
            ]

            if (not utils.OnWindows() and self._roslyn_path.endswith('.exe')):
                command.insert(0, 'mono')

            LOGGER.info('Starting OmniSharp server with: %s', command)

            solutionfile = os.path.basename(self._solution_path)
            self._filename_stdout = utils.CreateLogfile(
                LOGFILE_FORMAT.format(port=self._omnisharp_port,
                                      sln=solutionfile,
                                      std='stdout'))
            self._filename_stderr = utils.CreateLogfile(
                LOGFILE_FORMAT.format(port=self._omnisharp_port,
                                      sln=solutionfile,
                                      std='stderr'))

            with utils.OpenForStdHandle(self._filename_stderr) as fstderr:
                with utils.OpenForStdHandle(self._filename_stdout) as fstdout:
                    self._omnisharp_phandle = utils.SafePopen(command,
                                                              stdout=fstdout,
                                                              stderr=fstderr)

            LOGGER.info('Started OmniSharp server')
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
    def _StartServer(self, request_data, project_directory=None):
        with self._server_state_mutex:
            if self._server_started:
                return

            self._server_started = True

            _logger.info('Starting dart Language Server...')

            if project_directory:
                self._project_dir = project_directory
            else:
                self._project_dir = _FindProjectDir(
                    os.path.dirname(request_data['filepath']))

            self._workspace_path = self._project_dir

            command = [
                PATH_TO_DART,
                '--force_trace_level=verbose',
            ]

            _logger.debug('Starting dart-server with the following command: '
                          '{0}'.format(' '.join(command)))

            self._server_stderr = utils.CreateLogfile('dart_stderr_')
            with utils.OpenForStdHandle(self._server_stderr) as stderr:
                self._server_handle = utils.SafePopen(command,
                                                      stdin=PIPE,
                                                      stdout=PIPE,
                                                      stderr=stderr)

            self._connection = (
                language_server_completer.StandardIOLanguageServerConnection(
                    self._server_handle.stdin, self._server_handle.stdout,
                    self.GetDefaultNotificationHandler()))

            self._connection.Start()

            try:
                self._connection.AwaitServerConnection()
            except language_server_completer.LanguageServerConnectionTimeout:
                _logger.error('dart failed to start, or did not connect '
                              'successfully')
                self._StopServer()
                return

        _logger.info('dart Language Server started')

        self.SendInitialize(request_data)
Exemplo n.º 16
0
    def _StartServer(self, request_data):
        with self._server_state_mutex:
            if self._server_started:
                return

            self._server_started = True
            _logger.info('Starting Vue Language Server')

            command = [LANGUAGE_SERVER_HOME, '--stdio']

            self._server_stderr = utils.CreateLogfile('vls_stderr_')

            with utils.OpenForStdHandle(self._server_stderr) as stderr:
                self._server_handle = utils.SafePopen(command,
                                                      stdin=PIPE,
                                                      stdout=PIPE,
                                                      stderr=stderr)

            if not self._ServerIsRunning():
                _logger.error('Vue Language Server failed to start')
                return

            _logger.info('Vue Language Server started')

            self._connection = language_server_completer.StandardIOLanguageServerConnection(
                self._server_handle.stdin, self._server_handle.stdout,
                self.GetDefaultNotificationHandler())

            self._connection.Start()

            try:
                self._connection.AwaitServerConnection()
            except language_server_completer.LanguageServerConnectionTimeout:
                _logger.error(
                    'Vue Language Server failed to start, or did not connect successfully'
                )
                self._StopServer()
                return

            self.SendInitialize(request_data)
Exemplo n.º 17
0
    def StartServer(self, request_data, project_directory=None):
        with self._server_state_mutex:
            if self._server_started:
                return

            # We have to get the settings before starting the server, as this call
            # might throw UnknownExtraConf.
            extra_conf_dir = self._GetSettingsFromExtraConf(request_data)

            self._server_started = True

            LOGGER.info('Starting jdt.ls Language Server...')

            if project_directory:
                self._java_project_dir = project_directory
            else:
                self._java_project_dir = _FindProjectDir(
                    os.path.dirname(request_data['filepath']))

            self._workspace_path = _WorkspaceDirForProject(
                self._java_project_dir, self._use_clean_workspace)

            command = [
                PATH_TO_JAVA,
                '-Dfile.encoding=UTF-8',
                '-Declipse.application=org.eclipse.jdt.ls.core.id1',
                '-Dosgi.bundles.defaultStartLevel=4',
                '-Declipse.product=org.eclipse.jdt.ls.core.product',
                '-Dlog.level=ALL',
                '-jar',
                self._launcher_path,
                '-configuration',
                self._launcher_config,
                '-data',
                self._workspace_path,
            ]

            LOGGER.debug('Starting java-server with the following command: %s',
                         command)

            self._server_stderr = utils.CreateLogfile('jdt.ls_stderr_')
            with utils.OpenForStdHandle(self._server_stderr) as stderr:
                self._server_handle = utils.SafePopen(command,
                                                      stdin=PIPE,
                                                      stdout=PIPE,
                                                      stderr=stderr)

            self._connection = (
                language_server_completer.StandardIOLanguageServerConnection(
                    self._server_handle.stdin, self._server_handle.stdout,
                    self.GetDefaultNotificationHandler()))

            self._connection.Start()

            try:
                self._connection.AwaitServerConnection()
            except language_server_completer.LanguageServerConnectionTimeout:
                LOGGER.error('jdt.ls failed to start, or did not connect '
                             'successfully')
                self._StopServer()
                return

        LOGGER.info('jdt.ls Language Server started')

        self.SendInitialize(request_data, extra_conf_dir=extra_conf_dir)
Exemplo n.º 18
0
    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')
Exemplo n.º 19
0
    def StartServer(self,
                    request_data,
                    project_directory=None,
                    wipe_workspace=False,
                    wipe_config=False):
        with self._server_state_mutex:
            LOGGER.info('Starting jdt.ls Language Server...')

            if project_directory:
                self._java_project_dir = project_directory
            else:
                self._java_project_dir = _FindProjectDir(
                    os.path.dirname(request_data['filepath']))

            self._workspace_path = _WorkspaceDirForProject(
                self._workspace_root_path, self._java_project_dir,
                self._use_clean_workspace)

            if not self._use_clean_workspace and wipe_workspace:
                if os.path.isdir(self._workspace_path):
                    LOGGER.info('Wiping out workspace {0}'.format(
                        self._workspace_path))
                    shutil.rmtree(self._workspace_path)

            self._launcher_config = _LauncherConfiguration(
                self._workspace_root_path, wipe_config)

            command = [
                PATH_TO_JAVA,
                '-Dfile.encoding=UTF-8',
                '-Declipse.application=org.eclipse.jdt.ls.core.id1',
                '-Dosgi.bundles.defaultStartLevel=4',
                '-Declipse.product=org.eclipse.jdt.ls.core.product',
                '-Dlog.level=ALL',
                '-jar',
                self._launcher_path,
                '-configuration',
                self._launcher_config,
                '-data',
                self._workspace_path,
            ]

            LOGGER.debug('Starting java-server with the following command: %s',
                         command)

            self._server_stderr = utils.CreateLogfile('jdt.ls_stderr_')
            with utils.OpenForStdHandle(self._server_stderr) as stderr:
                self._server_handle = utils.SafePopen(command,
                                                      stdin=PIPE,
                                                      stdout=PIPE,
                                                      stderr=stderr)

            self._connection = (
                language_server_completer.StandardIOLanguageServerConnection(
                    self._server_handle.stdin, self._server_handle.stdout,
                    self.GetDefaultNotificationHandler()))

            self._connection.Start()

            try:
                self._connection.AwaitServerConnection()
            except language_server_completer.LanguageServerConnectionTimeout:
                LOGGER.error('jdt.ls failed to start, or did not connect '
                             'successfully')
                self.Shutdown()
                return False

        LOGGER.info('jdt.ls Language Server started')

        return True