def test_CodepointsToUTF16CodeUnitsAndReverse( self ):
   for line_value, codepoints, code_units in [ ( '', 0, 0 ),
       ( 'abcdef', 1, 1 ),
       ( 'abcdef', 2, 2 ),
       ( 'abc', 4, 4 ),
       ( '😉test', len( '😉' ), 2 ),
       ( '😉', len( '😉' ), 2 ),
       ( '😉test', len( '😉' ) + 1, 3 ),
       ( 'te😉st', 1, 1 ),
       ( 'te😉st', 2 + len( '😉' ) + 1, 5 ),
   ]:
     with self.subTest( line_value = line_value,
                        codepoints = codepoints,
                        code_units = code_units ):
       assert_that( lsp.CodepointsToUTF16CodeUnits( line_value, codepoints ),
                    equal_to( code_units ) )
       assert_that( lsp.UTF16CodeUnitsToCodepoints( line_value, code_units ),
                    equal_to( codepoints ) )
Beispiel #2
0
    def GetDetailedDiagnostic(self, request_data):
        self._UpdateServerWithFileContents(request_data)

        current_line_lsp = request_data['line_num'] - 1
        current_file = request_data['filepath']

        if not self._latest_diagnostics:
            return responses.BuildDisplayMessageResponse(
                'Diagnostics are not ready yet.')

        with self._server_info_mutex:
            diagnostics = list(
                self._latest_diagnostics[lsp.FilePathToUri(current_file)])

        if not diagnostics:
            return responses.BuildDisplayMessageResponse(
                'No diagnostics for current file.')

        current_column = lsp.CodepointsToUTF16CodeUnits(
            GetFileLines(request_data, current_file)[current_line_lsp],
            request_data['column_codepoint'])
        minimum_distance = None

        message = 'No diagnostics for current line.'
        for diagnostic in diagnostics:
            start = diagnostic['range']['start']
            end = diagnostic['range']['end']
            if current_line_lsp < start['line'] or end[
                    'line'] < current_line_lsp:
                continue
            point = {'line': current_line_lsp, 'character': current_column}
            distance = DistanceOfPointToRange(point, diagnostic['range'])
            if minimum_distance is None or distance < minimum_distance:
                message = diagnostic['message']
                if distance == 0:
                    break
                minimum_distance = distance

        return responses.BuildDisplayMessageResponse(message)
def CodepointsToUTF16CodeUnitsAndReverse_test(line_value, codepoints,
                                              code_units):
    assert_that(lsp.CodepointsToUTF16CodeUnits(line_value, codepoints),
                equal_to(code_units))
    assert_that(lsp.UTF16CodeUnitsToCodepoints(line_value, code_units),
                equal_to(codepoints))