Пример #1
0
 def ForceCompileAndDiagnostics(self):
     if not self.NativeFiletypeCompletionUsable():
         vimsupport.PostVimMessage(
             'Native filetype completion not supported for current file, '
             'cannot force recompilation.',
             warning=False)
         return False
     vimsupport.PostVimMessage(
         'Forcing compilation, this will block Vim until done.',
         warning=False)
     self.OnFileReadyToParse()
     self.HandleFileParseRequest(block=True)
     vimsupport.PostVimMessage('Diagnostics refreshed', warning=False)
     return True
Пример #2
0
  def ComputeCandidatesInner( self, request_data ):
    if not self._omnifunc:
      return []

    try:
      return_value = int( vim.eval( self._omnifunc + '(1,"")' ) )
      if return_value < 0:
        # FIXME: Technically, if the return is -1 we should raise an error
        return []

      omnifunc_call = [ self._omnifunc,
                        "(0,'",
                        vimsupport.EscapeForVim( request_data[ 'query' ] ),
                        "')" ]

      items = vim.eval( ''.join( omnifunc_call ) )

      if isinstance( items, dict ) and 'words' in items:
        items = items[ 'words' ]

      if not hasattr( items, '__iter__' ):
        raise TypeError( OMNIFUNC_NOT_LIST )

      return list( filter( bool, items ) )

    except ( TypeError, ValueError, vim.error ) as error:
      vimsupport.PostVimMessage(
        OMNIFUNC_RETURNED_BAD_VALUE + ' ' + str( error ) )
      return []
Пример #3
0
    def _NotifyUserIfServerCrashed(self):
        if self._user_notified_about_crash or self.IsServerAlive():
            return
        self._user_notified_about_crash = True

        return_code = self._server_popen.poll()
        if return_code == server_utils.CORE_UNEXPECTED_STATUS:
            error_message = CORE_UNEXPECTED_MESSAGE
        elif return_code == server_utils.CORE_MISSING_STATUS:
            error_message = CORE_MISSING_MESSAGE
        elif return_code == server_utils.CORE_PYTHON2_STATUS:
            error_message = CORE_PYTHON2_MESSAGE
        elif return_code == server_utils.CORE_PYTHON3_STATUS:
            error_message = CORE_PYTHON3_MESSAGE
        elif return_code == server_utils.CORE_OUTDATED_STATUS:
            error_message = CORE_OUTDATED_MESSAGE
        else:
            error_message = EXIT_CODE_UNEXPECTED_MESSAGE.format(
                code=return_code)

        server_stderr = '\n'.join(
            utils.ToUnicode(self._server_popen.stderr.read()).splitlines())
        if server_stderr:
            self._logger.error(server_stderr)

        error_message = SERVER_SHUTDOWN_MESSAGE + ' ' + error_message
        self._logger.error(error_message)
        vimsupport.PostVimMessage(error_message)
Пример #4
0
    def ShowDetailedDiagnostic(self):
        with HandleServerException():
            detailed_diagnostic = BaseRequest.PostDataToHandler(
                BuildRequestData(), 'detailed_diagnostic')

            if 'message' in detailed_diagnostic:
                vimsupport.PostVimMessage(detailed_diagnostic['message'],
                                          warning=False)
Пример #5
0
def DisplayServerException(exception, truncate=False):
    serialized_exception = str(exception)

    # We ignore the exception about the file already being parsed since it comes
    # up often and isn't something that's actionable by the user.
    if 'already being parsed' in serialized_exception:
        return
    vimsupport.PostVimMessage(serialized_exception, truncate=truncate)
    def _EchoDiagnosticForLine(self, line_num):
        buffer_num = vim.current.buffer.number
        diags = self._buffer_number_to_line_to_diags[buffer_num][line_num]
        if not diags:
            if self._diag_message_needs_clearing:
                # Clear any previous diag echo
                vimsupport.PostVimMessage('', warning=False)
                self._diag_message_needs_clearing = False
            return

        first_diag = diags[0]
        text = first_diag['text']
        if first_diag.get('fixit_available', False):
            text += ' (FixIt)'

        vimsupport.PostVimMessage(text, warning=False, truncate=True)
        self._diag_message_needs_clearing = True
Пример #7
0
    def ShowDiagnostics(self):
        if not self.ForceCompileAndDiagnostics():
            return

        if not self._PopulateLocationListWithLatestDiagnostics():
            vimsupport.PostVimMessage('No warnings or errors detected.',
                                      warning=False)
            return

        if self._user_options['open_loclist_on_icm_diags']:
            vimsupport.OpenLocationList(focus=True)
Пример #8
0
    def _HandleFixitResponse(self):
        if not len(self._response['fixits']):
            vimsupport.PostVimMessage('No fixits found for current line',
                                      warning=False)
        else:
            try:
                fixit_index = 0

                # When there are multiple fixit suggestions, present them as a list to
                # the user hand have her choose which one to apply.
                if len(self._response['fixits']) > 1:
                    fixit_index = vimsupport.SelectFromList(
                        "Multiple FixIt suggestions are available at this location. "
                        "Which one would you like to apply?",
                        [fixit['text'] for fixit in self._response['fixits']])

                vimsupport.ReplaceChunks(
                    self._response['fixits'][fixit_index]['chunks'])
            except RuntimeError as e:
                vimsupport.PostVimMessage(str(e))
Пример #9
0
    def ToggleLogs(self, *filenames):
        logfiles = self.GetLogfiles()
        if not filenames:
            vimsupport.PostVimMessage('Available logfiles are:\n'
                                      '{0}'.format('\n'.join(
                                          sorted(list(logfiles)))))
            return

        for filename in set(filenames):
            if filename not in logfiles:
                continue

            logfile = logfiles[filename]

            if not vimsupport.BufferIsVisibleForFilename(logfile):
                self._OpenLogfile(logfile)
                continue

            self._CloseLogfile(logfile)
Пример #10
0
 def RestartServer(self):
     vimsupport.PostVimMessage('Restarting ycmd server...')
     self._ShutdownServer()
     self._SetupServer()
Пример #11
0
 def _HandleMessageResponse(self):
     vimsupport.PostVimMessage(self._response['message'], warning=False)
Пример #12
0
 def _HandleBasicResponse(self):
     vimsupport.PostVimMessage(self._response, warning=False)