def _PreviousIdentifier(min_num_completion_start_chars, request_data): line_num = request_data['line_num'] - 1 column_num = request_data['column_num'] - 1 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]
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()
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)
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
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
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
def FindFirstValidChar(line, column): current_column = column while not utils.IsIdentifierChar(line[current_column]): current_column += 1 return current_column