Esempio 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', '-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)
Esempio n. 2
0
 def GetServerEnvironment(self):
     env = os.environ.copy()
     utils.SetEnviron(env, 'RUSTC', self._rustc_binary_path)
     if LOGGER.isEnabledFor(logging.DEBUG):
         utils.SetEnviron(env, 'RUST_LOG', 'rls=trace')
         utils.SetEnviron(env, 'RUST_BACKTRACE', '1')
     return env
Esempio n. 3
0
 def GetServerEnvironment(self):
     env = os.environ.copy()
     env['RUSTC'] = self._rustc_path
     if LOGGER.isEnabledFor(logging.DEBUG):
         env['RUST_LOG'] = 'rls=trace'
         env['RUST_BACKTRACE'] = '1'
     return env
Esempio n. 4
0
 def GetServerEnvironment(self):
     env = os.environ.copy()
     old_path = env['PATH']
     ra_bin_dir = os.path.join(self._rust_root, 'bin')
     env['PATH'] = ra_bin_dir + os.pathsep + old_path
     if LOGGER.isEnabledFor(logging.DEBUG):
         env['RA_LOG'] = 'rust_analyzer=trace'
     return env
Esempio n. 5
0
 def GetServerEnvironment(self):
     env = os.environ.copy()
     # Force RLS to use the rustc from the toolchain in third_party/rls.
     # TODO: allow users to pick a custom toolchain.
     utils.SetEnviron(env, 'RUSTC', RUSTC_EXECUTABLE)
     if LOGGER.isEnabledFor(logging.DEBUG):
         utils.SetEnviron(env, 'RUST_LOG', 'rls=trace')
         utils.SetEnviron(env, 'RUST_BACKTRACE', '1')
     return env
Esempio n. 6
0
    def ComputeSignaturesInner(self, request_data):
        self._Reload(request_data)
        try:
            items = self._SendRequest(
                'signatureHelp',
                {
                    'file': request_data['filepath'],
                    'line': request_data['line_num'],
                    'offset': request_data['start_codepoint'],
                    # triggerReason - opitonal and tricky to populate
                })
        except RuntimeError:
            # We get an exception when there are no results, so squash it
            if LOGGER.isEnabledFor(logging.DEBUG):
                LOGGER.exception("No signatures from tsserver")
            return {}

        def MakeSignature(s):
            def GetTSDocs(docs_list):
                return '\n'.join(item['text'] for item in docs_list)

            label = _DisplayPartsToString(s['prefixDisplayParts'])
            parameters = []
            sep = _DisplayPartsToString(s['separatorDisplayParts'])
            for index, p in enumerate(s['parameters']):
                param = _DisplayPartsToString(p['displayParts'])
                start = len(label)
                end = start + len(param)

                label += param
                if index < len(s['parameters']) - 1:
                    label += sep

                parameters.append({
                    'documentation':
                    GetTSDocs(p.get('documentation', [])),
                    'label': [
                        utils.CodepointOffsetToByteOffset(label, start),
                        utils.CodepointOffsetToByteOffset(label, end)
                    ]
                })

            label += _DisplayPartsToString(s['suffixDisplayParts'])

            return {
                'documentation': GetTSDocs(s.get('documentation', [])),
                'label': label,
                'parameters': parameters
            }

        return {
            'activeSignature': items['selectedItemIndex'],
            'activeParameter': items['argumentIndex'],
            'signatures': [MakeSignature(s) for s in items['items']]
        }
Esempio n. 7
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' )
Esempio n. 8
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' )
Esempio n. 9
0
def GetClangdCommand(user_options):
    global CLANGD_COMMAND
    # None stands for we tried to fetch command and failed, therefore it is not
    # the default.
    if CLANGD_COMMAND != NOT_CACHED:
        LOGGER.info('Returning cached Clangd command: %s', CLANGD_COMMAND)
        return CLANGD_COMMAND
    CLANGD_COMMAND = None

    installed_clangd, resource_dir = GetClangdExecutableAndResourceDir(
        user_options)
    if not installed_clangd:
        return None

    CLANGD_COMMAND = [installed_clangd]
    clangd_args = user_options['clangd_args']
    put_resource_dir = False
    put_limit_results = False
    put_header_insertion_decorators = False
    put_log = False
    for arg in clangd_args:
        CLANGD_COMMAND.append(arg)
        put_resource_dir = put_resource_dir or arg.startswith('-resource-dir')
        put_limit_results = put_limit_results or arg.startswith(
            '-limit-results')
        put_header_insertion_decorators = (
            put_header_insertion_decorators
            or arg.startswith('-header-insertion-decorators'))
        put_log = put_log or arg.startswith('-log')
    if not put_header_insertion_decorators:
        CLANGD_COMMAND.append('-header-insertion-decorators=0')
    if resource_dir and not put_resource_dir:
        CLANGD_COMMAND.append('-resource-dir=' + resource_dir)
    if user_options['clangd_uses_ycmd_caching'] and not put_limit_results:
        CLANGD_COMMAND.append('-limit-results=500')
    if LOGGER.isEnabledFor(logging.DEBUG) and not put_log:
        CLANGD_COMMAND.append('-log=verbose')

    return CLANGD_COMMAND
Esempio n. 10
0
def GetClangdCommand( user_options ):
  global CLANGD_COMMAND
  # None stands for we tried to fetch command and failed, therefore it is not
  # the default.
  if CLANGD_COMMAND != NOT_CACHED:
    LOGGER.info( 'Returning cached Clangd command: %s', CLANGD_COMMAND )
    return CLANGD_COMMAND
  CLANGD_COMMAND = None

  installed_clangd, resource_dir = GetClangdExecutableAndResourceDir(
      user_options )
  if not installed_clangd:
    return None

  CLANGD_COMMAND = [ installed_clangd ]
  clangd_args = user_options[ 'clangd_args' ]
  put_resource_dir = False
  put_limit_results = False
  put_header_insertion_decorators = False
  put_log = False
  for arg in clangd_args:
    CLANGD_COMMAND.append( arg )
    put_resource_dir = put_resource_dir or arg.startswith( '-resource-dir' )
    put_limit_results = put_limit_results or arg.startswith( '-limit-results' )
    put_header_insertion_decorators = ( put_header_insertion_decorators or
                        arg.startswith( '-header-insertion-decorators' ) )
    put_log = put_log or arg.startswith( '-log' )
  if not put_header_insertion_decorators:
    CLANGD_COMMAND.append( '-header-insertion-decorators=0' )
  if resource_dir and not put_resource_dir:
    CLANGD_COMMAND.append( '-resource-dir=' + resource_dir )
  if user_options[ 'clangd_uses_ycmd_caching' ] and not put_limit_results:
    CLANGD_COMMAND.append( '-limit-results=500' )
  if LOGGER.isEnabledFor( logging.DEBUG ) and not put_log:
    CLANGD_COMMAND.append( '-log=verbose' )

  return CLANGD_COMMAND
Esempio n. 11
0
def _LogLevel():
    return 'verbose' if LOGGER.isEnabledFor(logging.DEBUG) else 'normal'
def _LogLevel():
  return 'verbose' if LOGGER.isEnabledFor( logging.DEBUG ) else 'normal'