예제 #1
0
def _PreviousIdentifier(min_num_completion_start_chars, request_data):
    line_num = request_data['line_num']
    column_num = request_data['column_num']
    filepath = request_data['filepath']
    contents_per_line = (
        request_data['file_data'][filepath]['contents'].split('\n'))
    line = contents_per_line[line_num]

    end_column = column_num

    while end_column > 0 and not utils.IsIdentifierChar(line[end_column - 1]):
        end_column -= 1

    # Look at the previous line if we reached the end of the current one
    if end_column == 0:
        try:
            line = contents_per_line[line_num - 1]
        except:
            return ""
        end_column = len(line)
        while end_column > 0 and not utils.IsIdentifierChar(
                line[end_column - 1]):
            end_column -= 1

    start_column = end_column
    while start_column > 0 and utils.IsIdentifierChar(line[start_column - 1]):
        start_column -= 1

    if end_column - start_column < min_num_completion_start_chars:
        return ""

    return line[start_column:end_column]
예제 #2
0
def PreviousIdentifier():
    line_num, column_num = vimsupport.CurrentLineAndColumn()
    buffer = vim.current.buffer
    line = buffer[line_num]

    end_column = column_num

    while end_column > 0 and not utils.IsIdentifierChar(line[end_column - 1]):
        end_column -= 1

    # Look at the previous line if we reached the end of the current one
    if end_column == 0:
        try:
            line = buffer[line_num - 1]
        except:
            return ""
        end_column = len(line)
        while end_column > 0 and not utils.IsIdentifierChar(
                line[end_column - 1]):
            end_column -= 1

    start_column = end_column
    while start_column > 0 and utils.IsIdentifierChar(line[start_column - 1]):
        start_column -= 1

    if end_column - start_column < MIN_NUM_CHARS:
        return ""

    return line[start_column:end_column]
예제 #3
0
def CurrentIdentifierFinished():
    current_column = vimsupport.CurrentColumn()
    previous_char_index = current_column - 1
    if previous_char_index < 0:
        return True
    line = vim.current.line
    try:
        previous_char = line[previous_char_index]
    except IndexError:
        return False

    if utils.IsIdentifierChar(previous_char):
        return False

    if (not utils.IsIdentifierChar(previous_char) and previous_char_index > 0
            and utils.IsIdentifierChar(line[previous_char_index - 1])):
        return True
    else:
        return line[:current_column].isspace()
예제 #4
0
    def AddIdentifierUnderCursor(self):
        cursor_identifier = vim.eval('expand("<cword>")')
        if not cursor_identifier:
            return

        stripped_cursor_identifier = ''.join(
            (x for x in cursor_identifier if utils.IsIdentifierChar(x)))
        if not stripped_cursor_identifier:
            return

        self.AddIdentifier(stripped_cursor_identifier)
예제 #5
0
def LastEnteredCharIsIdentifierChar():
    current_column = vimsupport.CurrentColumn()
    previous_char_index = current_column - 1
    if previous_char_index < 0:
        return False
    line = vim.current.line
    try:
        previous_char = line[previous_char_index]
    except IndexError:
        return False

    return utils.IsIdentifierChar(previous_char)
예제 #6
0
def CompletionStartColumn():
    """Returns the 0-based index where the completion string should start. So if
  the user enters:
    foo.bar^
  with the cursor being at the location of the caret, then the starting column
  would be the index of the letter 'b'.
  """

    line = vim.current.line
    start_column = vimsupport.CurrentColumn()

    while start_column > 0 and utils.IsIdentifierChar(line[start_column - 1]):
        start_column -= 1
    return start_column
예제 #7
0
 def FindIdentifierEnd(line, valid_char_column):
     identifier_end = valid_char_column
     while identifier_end < len(line) - 1 and utils.IsIdentifierChar(
             line[identifier_end + 1]):
         identifier_end += 1
     return identifier_end + 1
예제 #8
0
 def FindIdentifierStart(line, valid_char_column):
     identifier_start = valid_char_column
     while identifier_start > 0 and utils.IsIdentifierChar(
             line[identifier_start - 1]):
         identifier_start -= 1
     return identifier_start
예제 #9
0
 def FindFirstValidChar(line, column):
     current_column = column
     while not utils.IsIdentifierChar(line[current_column]):
         current_column += 1
     return current_column