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.
                fixits = self._response['fixits']
                if len(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 fixits])
                chosen_fixit = fixits[fixit_index]
                if chosen_fixit['resolve']:
                    self._request_data.update({'fixit': chosen_fixit})
                    response = self.PostDataToHandler(self._request_data,
                                                      'resolve_fixit')
                    fixits = response['fixits']
                    assert len(fixits) == 1
                    chosen_fixit = fixits[0]

                vimsupport.ReplaceChunks(chosen_fixit['chunks'],
                                         silent=self._command == 'Format')
            except RuntimeError as e:
                vimsupport.PostVimMessage(str(e))
Beispiel #2
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

                # If there is more than one fixit, we need to ask the user which one
                # should be applied.
                #
                # If there's only one, triggered by the FixIt subcommand (as opposed to
                # `RefactorRename`, for example) and whose `kind` is not `quicfix`, we
                # still need to as the user for confirmation.
                fixits = self._response['fixits']
                if (len(fixits) > 1
                        or (len(fixits) == 1 and self._command == 'FixIt'
                            and fixits[0].get('kind') != 'quickfix')):
                    fixit_index = vimsupport.SelectFromList(
                        "FixIt suggestion(s) available at this location. "
                        "Which one would you like to apply?",
                        [fixit['text'] for fixit in fixits])
                chosen_fixit = fixits[fixit_index]
                if chosen_fixit['resolve']:
                    self._request_data.update({'fixit': chosen_fixit})
                    response = self.PostDataToHandler(self._request_data,
                                                      'resolve_fixit')
                    fixits = response['fixits']
                    assert len(fixits) == 1
                    chosen_fixit = fixits[0]

                vimsupport.ReplaceChunks(chosen_fixit['chunks'],
                                         silent=self._command == 'Format')
            except RuntimeError as e:
                vimsupport.PostVimMessage(str(e))
Beispiel #3
0
  def ToggleLogs( self, *filenames ):
    logfiles = self.GetLogfiles()
    if not filenames:
      sorted_logfiles = sorted( list( logfiles ) )
      try:
        logfile_index = vimsupport.SelectFromList(
          'Which logfile do you wish to open (or close if already open)?',
          sorted_logfiles )
      except RuntimeError as e:
        vimsupport.PostVimMessage( str( e ) )
        return

      logfile = logfiles[ sorted_logfiles[ logfile_index ] ]
      if not vimsupport.BufferIsVisibleForFilename( logfile ):
        self._OpenLogfile( logfile )
      else:
        self._CloseLogfile( logfile )
      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 )
Beispiel #4
0
    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))