Example #1
0
  def _HasCompletionsThatCouldBeCompletedWithMoreText_NewerVim( self,
                                                                completions ):
    completed_item = vimsupport.GetVariableValue( 'v:completed_item' )
    if not completed_item:
      return False

    completed_word = completed_item[ 'word' ]
    if not completed_word:
      return False

    # Sometime CompleteDone is called after the next character is inserted
    # If so, use inserted character to filter possible completions further
    text = vimsupport.TextBeforeCursor()
    reject_exact_match = True
    if text and text[ -1 ] != completed_word[ -1 ]:
      reject_exact_match = False
      completed_word += text[ -1 ]

    for completion in completions:
      word = ConvertCompletionDataToVimData( completion )[ 'word' ]
      if reject_exact_match and word == completed_word:
        continue
      if word.startswith( completed_word ):
        return True
    return False
Example #2
0
  def _HasCompletionsThatCouldBeCompletedWithMoreText_NewerVim( self,
                                                                completions ):
    completed_item = vimsupport.GetVariableValue( 'v:completed_item' )
    if not completed_item:
      return False

    completed_word = completed_item[ 'word' ]
    if not completed_word:
      return False

    # Sometime CompleteDone is called after the next character is inserted
    # If so, use inserted character to filter possible completions further
    text = vimsupport.TextBeforeCursor()
    reject_exact_match = True
    if text and text[ -1 ] != completed_word[ -1 ]:
      reject_exact_match = False
      completed_word += text[ -1 ]

    for completion in completions:
      word = ConvertCompletionDataToVimData( completion )[ 'word' ]
      if reject_exact_match and word == completed_word:
        continue
      if word.startswith( completed_word ):
        return True
    return False
 def _FilterToMatchingCompletions_NewerVim(self, completions, full_match_only):
     """ Filter to completions matching the item Vim said was completed """
     completed = vimsupport.GetVariableValue("v:completed_item")
     for completion in completions:
         item = ConvertCompletionDataToVimData(completion)
         match_keys = ["word", "abbr", "menu", "info"] if full_match_only else ["word"]
         matcher = lambda key: completed.get(key, "") == item.get(key, "")
         if all([matcher(i) for i in match_keys]):
             yield completion
Example #4
0
 def _FilterToMatchingCompletions_NewerVim(self, completions,
                                           full_match_only):
     """ Filter to completions matching the item Vim said was completed """
     completed = vimsupport.GetVariableValue('v:completed_item')
     for completion in completions:
         item = ConvertCompletionDataToVimData(completion)
         match_keys = (["word", "abbr", "menu", "info"]
                       if full_match_only else ['word'])
         matcher = lambda key: completed.get(key, "") == item.get(key, "")
         if all([matcher(i) for i in match_keys]):
             yield completion
Example #5
0
  def _HasCompletionsThatCouldBeCompletedWithMoreText( self,
                                                       completed_item,
                                                       completions ):
    if not completed_item:
      return False

    completed_word = utils.ToUnicode( completed_item[ 'word' ] )
    if not completed_word:
      return False

    # Sometimes CompleteDone is called after the next character is inserted.
    # If so, use inserted character to filter possible completions further.
    text = vimsupport.TextBeforeCursor()
    reject_exact_match = True
    if text and text[ -1 ] != completed_word[ -1 ]:
      reject_exact_match = False
      completed_word += text[ -1 ]

    for index, completion in enumerate( completions ):
      word = utils.ToUnicode(
          ConvertCompletionDataToVimData( index, completion )[ 'word' ] )
      if reject_exact_match and word == completed_word:
        continue
      if word.startswith( completed_word ):
        return True
    return False
Example #6
0
 def _HasCompletionsThatCouldBeCompletedWithMoreText_OlderVim(
         self, completions):
     # No support for multiple line completions
     text = vimsupport.TextBeforeCursor()
     for completion in completions:
         word = ConvertCompletionDataToVimData(completion)['word']
         for i in range(1, len(word) - 1):  # Excluding full word
             if text[-1 * i:] == word[:i]:
                 return True
     return False
  def _FilterToMatchingCompletions( self, completions, full_match_only ):
    """Filter to completions matching the item Vim said was completed"""
    completed = vimsupport.GetVariableValue( 'v:completed_item' )
    for completion in completions:
      item = ConvertCompletionDataToVimData( completion )
      match_keys = ( [ "word", "abbr", "menu", "info" ] if full_match_only
                      else [ 'word' ] )

      def matcher( key ):
        return ( utils.ToUnicode( completed.get( key, "" ) ) ==
                 utils.ToUnicode( item.get( key, "" ) ) )

      if all( [ matcher( i ) for i in match_keys ] ):
        yield completion
Example #8
0
    def _FilterToMatchingCompletions(self, completed_item, completions,
                                     full_match_only):
        """Filter to completions matching the item Vim said was completed"""
        match_keys = (["word", "abbr", "menu", "info"]
                      if full_match_only else ['word'])

        for index, completion in enumerate(completions):
            item = ConvertCompletionDataToVimData(index, completion)

            def matcher(key):
                return (utils.ToUnicode(completed_item.get(
                    key, "")) == utils.ToUnicode(item.get(key, "")))

            if all([matcher(i) for i in match_keys]):
                yield completion
    def Response(self):
        response = self.HandleFuture(self._response_future,
                                     truncate_message=True,
                                     display_message=True)

        if not response or not response['completion']:
            return {'completion': []}

        # Vim may not be able to convert the 'errors' entry to its internal format
        # so we remove it from the response.
        errors = response.pop('errors', [])
        for e in errors:
            exception = MakeServerException(e)
            _logger.error(exception)
            DisplayServerException(exception, truncate_message=True)

        response['completion'] = ConvertCompletionDataToVimData(
            response['completion'])
        return response