コード例 #1
0
 def EchoUserCommandsHelpMessage(self):
     subcommands = self.DefinedSubcommands()
     if subcommands:
         vimsupport.EchoText(
             'Supported commands are:\n' + '\n'.join(subcommands) +
             '\nSee the docs for information on what they do.')
     else:
         vimsupport.EchoText('No supported subcommands')
コード例 #2
0
    def ShowDetailedDiagnostic(self):
        current_line, current_column = vimsupport.CurrentLineAndColumn()

        # CurrentLineAndColumn() numbers are 0-based, clang numbers are 1-based
        current_line += 1
        current_column += 1

        current_file = vim.current.buffer.name

        if not self.diagnostic_store:
            vimsupport.PostVimMessage("No diagnostic for current line!")
            return

        diagnostics = self.diagnostic_store[current_file][current_line]
        if not diagnostics:
            vimsupport.PostVimMessage("No diagnostic for current line!")
            return

        closest_diagnostic = None
        distance_to_closest_diagnostic = 999

        for diagnostic in diagnostics:
            distance = abs(current_column - diagnostic.column_number_)
            if distance < distance_to_closest_diagnostic:
                distance_to_closest_diagnostic = distance
                closest_diagnostic = diagnostic

        vimsupport.EchoText(closest_diagnostic.long_formatted_text_)
コード例 #3
0
 def _HandleFixitResponse(self):
     if not len(self._response['fixits']):
         vimsupport.EchoText("No fixits found for current line")
     else:
         chunks = self._response['fixits'][0]['chunks']
         try:
             vimsupport.ReplaceChunks(chunks)
         except RuntimeError as e:
             vimsupport.PostMultiLineNotice(e.message)
コード例 #4
0
ファイル: youcompleteme.py プロジェクト: newli/YouCompleteMe
 def ShowDetailedDiagnostic(self):
     if not self.IsServerAlive():
         return
     try:
         debug_info = BaseRequest.PostDataToHandler(BuildRequestData(),
                                                    'detailed_diagnostic')
         if 'message' in debug_info:
             vimsupport.EchoText(debug_info['message'])
     except ServerError as e:
         vimsupport.PostVimMessage(str(e))
コード例 #5
0
    def _HandleFixitResponse(self):
        if not len(self._response['fixits']):
            vimsupport.EchoText("No fixits found for current line")
        else:
            chunks = self._response['fixits'][0]['chunks']

            vimsupport.ReplaceChunksList(chunks)

            vimsupport.EchoTextVimWidth("FixIt applied " + str(len(chunks)) +
                                        " changes")
コード例 #6
0
 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.EchoText( '', False )
       self._diag_message_needs_clearing = False
     return
   vimsupport.EchoTextVimWidth( diags[ 0 ][ 'text' ] )
   self._diag_message_needs_clearing = True
コード例 #7
0
    def RunPostCommandActionsIfNeeded(self):
        if not self.Done() or not self._response:
            return

        if self._is_goto_command:
            if isinstance(self._response, list):
                defs = [_BuildQfListItem(x) for x in self._response]
                vim.eval('setqflist( %s )' % repr(defs))
                vim.eval('youcompleteme#OpenGoToList()')
            else:
                vimsupport.JumpToLocation(self._response['filepath'],
                                          self._response['line_num'],
                                          self._response['column_num'])
        elif 'message' in self._response:
            vimsupport.EchoText(self._response['message'])
コード例 #8
0
    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.EchoText('', False)
                self._diag_message_needs_clearing = False
            return

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

        vimsupport.EchoTextVimWidth(text)
        self._diag_message_needs_clearing = True
コード例 #9
0
ファイル: command_request.py プロジェクト: neilzhou/vim
    def _HandleFixitResponse(self):
        if not len(self._response['fixits']):
            vimsupport.EchoText("No fixits found for current line")
        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.PostMultiLineNotice(str(e))
コード例 #10
0
    def _HandleFixitResponse(self):
        if not len(self._response['fixits']):
            vimsupport.EchoText("No fixits found for current line")
        else:
            fixit = self._response['fixits'][0]

            # We need to track the difference in length, but ensuring we apply fixes
            # in ascending order of insertion point.
            fixit['chunks'].sort(key=lambda chunk: (str(chunk['range'][
                'start']['line_num']) + ',' + str(chunk['range']['start'][
                    'column_num'])))

            # Remember the line number we're processing. Negative line number means we
            # haven't processed any lines yet (by nature of being not equal to any
            # real line number).
            last_line = -1

            # Counter of changes applied, so the user has a mental picture of the
            # undo history this change is creating.
            num_fixed = 0
            line_delta = 0
            for chunk in fixit['chunks']:
                if chunk['range']['start']['line_num'] != last_line:
                    # If this chunk is on a different line than the previous chunk,
                    # then ignore previous deltas (as offsets won't have changed).
                    last_line = chunk['range']['end']['line_num']
                    char_delta = 0

                (new_line_delta, new_char_delta) = vimsupport.ReplaceChunk(
                    chunk['range']['start'], chunk['range']['end'],
                    chunk['replacement_text'], line_delta, char_delta)
                line_delta += new_line_delta
                char_delta += new_char_delta

                num_fixed = num_fixed + 1

            vimsupport.EchoTextVimWidth("FixIt applied " + str(num_fixed) +
                                        " changes")
コード例 #11
0
 def _HandleMessageResponse(self):
     vimsupport.EchoText(self._response['message'])
コード例 #12
0
 def _HandleBasicResponse(self):
     vimsupport.EchoText(self._response)
コード例 #13
0
 def _HandleBooleanResponse(self):
     if self._response:
         return vimsupport.EchoText('Yes')
     vimsupport.EchoText('No')