コード例 #1
0
ファイル: base.py プロジェクト: wjain/YouCompleteMe
def AdjustCandidateInsertionText(candidates):
    """This function adjusts the candidate insertion text to take into account the
  text that's currently in front of the cursor.

  For instance ('|' represents the cursor):
    1. Buffer state: 'foo.|bar'
    2. A completion candidate of 'zoobar' is shown and the user selects it.
    3. Buffer state: 'foo.zoobar|bar' instead of 'foo.zoo|bar' which is what the
    user wanted.

  This function changes candidates to resolve that issue.

  It could be argued that the user actually wants the final buffer state to be
  'foo.zoobar|' (the cursor at the end), but that would be much more difficult
  to implement and is probably not worth doing.
  """
    def NewCandidateInsertionText(to_insert, word_after_cursor):
        if to_insert.endswith(word_after_cursor):
            return to_insert[:-len(word_after_cursor)]
        return to_insert

    match = re.search(r'^(\w+)', vimsupport.TextAfterCursor())
    if not match:
        return candidates

    new_candidates = []

    word_after_cursor = match.group(1)
    for candidate in candidates:
        if type(candidate) is dict:
            new_candidate = candidate.copy()

            if not 'abbr' in new_candidate:
                new_candidate['abbr'] = new_candidate['word']

            new_candidate['word'] = NewCandidateInsertionText(
                new_candidate['word'], word_after_cursor)

            new_candidates.append(new_candidate)

        elif type(candidate) is str:
            new_candidates.append({
                'abbr':
                candidate,
                'word':
                NewCandidateInsertionText(candidate, word_after_cursor)
            })
    return new_candidates
コード例 #2
0
def AdjustCandidateInsertionText(candidates):
    """This function adjusts the candidate insertion text to take into account the
  text that's currently in front of the cursor.

  For instance ('|' represents the cursor):
    1. Buffer state: 'foo.|bar'
    2. A completion candidate of 'zoobar' is shown and the user selects it.
    3. Buffer state: 'foo.zoobar|bar' instead of 'foo.zoo|bar' which is what the
    user wanted.

  This function changes candidates to resolve that issue.

  It could be argued that the user actually wants the final buffer state to be
  'foo.zoobar|' (the cursor at the end), but that would be much more difficult
  to implement and is probably not worth doing.
  """
    def NewCandidateInsertionText(to_insert, text_after_cursor):
        overlap_len = OverlapLength(to_insert, text_after_cursor)
        if overlap_len:
            return to_insert[:-overlap_len]
        return to_insert

    text_after_cursor = vimsupport.TextAfterCursor()
    if not text_after_cursor:
        return candidates

    new_candidates = []
    for candidate in candidates:
        if isinstance(candidate, dict):
            new_candidate = candidate.copy()

            if 'abbr' not in new_candidate:
                new_candidate['abbr'] = new_candidate['word']

            new_candidate['word'] = NewCandidateInsertionText(
                new_candidate['word'], text_after_cursor)

            new_candidates.append(new_candidate)

        elif isinstance(candidate, str) or isinstance(candidate, bytes):
            new_candidates.append({
                'abbr':
                candidate,
                'word':
                NewCandidateInsertionText(candidate, text_after_cursor)
            })
    return new_candidates
コード例 #3
0
def TextAfterCursor_EncodedUnicode_test( *args ):
  eq_( vimsupport.TextAfterCursor(), u'ДД' )