def CompletionStartCodepoint(line_value, column_num, filetype): """Returns the 1-based codepoint index where the completion query should start. So if the user enters: ƒøø.∫å®^ with the cursor being at the location of the caret (so the character *AFTER* '®'), then the starting column would be the index of the character '∫' (i.e. 5, not its byte index).""" # NOTE: column_num and other numbers on the wire are byte indices, but we need # to walk codepoints for identifier checks. codepoint_column_num = ByteOffsetToCodepointOffset(line_value, column_num) unicode_line_value = ToUnicode(line_value) # -1 and then +1 to account for difference between 0-based and 1-based # indices/columns codepoint_start_column = StartOfLongestIdentifierEndingAtIndex( unicode_line_value, codepoint_column_num - 1, filetype) + 1 return codepoint_start_column
def CompletionStartColumn(line_value, column_num, filetype): """Returns the 1-based index where the completion query should start. So if the user enters: foo.bar^ with the cursor being at the location of the caret (so the character *AFTER* 'r'), then the starting column would be the index of the letter 'b'.""" # NOTE: column_num and other numbers on the wire are byte indices, but we need # to walk codepoints for identifier checks. utf8_line_value = ToUtf8IfNeeded(line_value) unicode_line_value = ToUnicodeIfNeeded(line_value) codepoint_column_num = len( unicode(utf8_line_value[:column_num - 1], 'utf8')) + 1 # -1 and then +1 to account for difference betwen 0-based and 1-based # indices/columns codepoint_start_column = StartOfLongestIdentifierEndingAtIndex( unicode_line_value, codepoint_column_num - 1, filetype) + 1 return len( unicode_line_value[:codepoint_start_column - 1].encode('utf8')) + 1