Exemplo n.º 1
0
 def _QuickFixToDiagnostic(self, request_data, quick_fix):
     filename = quick_fix["FileName"]
     location = _BuildLocation(request_data, filename, quick_fix['Line'],
                               quick_fix['Column'])
     location_range = responses.Range(location, location)
     return responses.Diagnostic(list(), location, location_range,
                                 quick_fix["Text"],
                                 quick_fix["LogLevel"].upper())
Exemplo n.º 2
0
    def _QuickFixToDiagnostic(self, quick_fix):
        filename = quick_fix["FileName"]

        location = responses.Location(quick_fix["Line"], quick_fix["Column"],
                                      filename)
        location_range = responses.Range(location, location)
        return responses.Diagnostic(list(), location, location_range,
                                    quick_fix["Text"],
                                    quick_fix["LogLevel"].upper())
Exemplo n.º 3
0
    def _TsDiagnosticToYcmdDiagnostic(self, request_data, ts_diagnostic):
        filepath = request_data['filepath']

        ts_fixes = self._SendRequest(
            'getCodeFixes', {
                'file': filepath,
                'startLine': ts_diagnostic['startLocation']['line'],
                'startOffset': ts_diagnostic['startLocation']['offset'],
                'endLine': ts_diagnostic['endLocation']['line'],
                'endOffset': ts_diagnostic['endLocation']['offset'],
                'errorCodes': [ts_diagnostic['code']]
            })
        location = responses.Location(request_data['line_num'],
                                      request_data['column_num'], filepath)

        fixits = []
        for fix in ts_fixes:
            description = fix['description']
            # TSServer returns these fixits for every error in JavaScript files.
            # Ignore them since they are not useful.
            if description in [
                    'Ignore this error message',
                    'Disable checking for this file'
            ]:
                continue

            fixit = responses.FixIt(
                location, _BuildFixItForChanges(request_data, fix['changes']),
                description)
            fixits.append(fixit)

        contents = GetFileLines(request_data, filepath)

        ts_start_location = ts_diagnostic['startLocation']
        ts_start_line = ts_start_location['line']
        start_offset = utils.CodepointOffsetToByteOffset(
            contents[ts_start_line - 1], ts_start_location['offset'])

        ts_end_location = ts_diagnostic['endLocation']
        ts_end_line = ts_end_location['line']
        end_offset = utils.CodepointOffsetToByteOffset(
            contents[ts_end_line - 1], ts_end_location['offset'])

        location_start = responses.Location(ts_start_line, start_offset,
                                            filepath)
        location_end = responses.Location(ts_end_line, end_offset, filepath)

        location_extent = responses.Range(location_start, location_end)

        return responses.Diagnostic([location_extent],
                                    location_start,
                                    location_extent,
                                    ts_diagnostic['message'],
                                    'ERROR',
                                    fixits=fixits)
Exemplo n.º 4
0
def _SwiftDiagnosticWithColumnToYcmdDiagnostic(filename,
                                               split_lines,
                                               swift_diagnostic,
                                               computed_line=None):
    start_col = swift_diagnostic.column
    end_col = start_col + 1
    line = computed_line if computed_line else swift_diagnostic.line
    location = _BuildLocation(split_lines, filename, line, start_col)
    location_end = _BuildLocation(split_lines, filename, line, end_col)
    location_extent = responses.Range(location, location_end)

    return responses.Diagnostic(list(), location, location_extent,
                                swift_diagnostic.description,
                                swift_diagnostic.GetYCMDSeverity())
Exemplo n.º 5
0
 def _QuickFixToDiagnostic(self, request_data, quick_fix):
     filename = quick_fix["FileName"]
     # NOTE: end of diagnostic range returned by the OmniSharp server is not
     # included.
     location = _BuildLocation(request_data, filename, quick_fix['Line'],
                               quick_fix['Column'])
     location_end = _BuildLocation(request_data, filename,
                                   quick_fix['EndLine'],
                                   quick_fix['EndColumn'])
     if not location_end:
         location_end = location
     location_extent = responses.Range(location, location_end)
     return responses.Diagnostic([], location, location_extent,
                                 quick_fix['Text'],
                                 quick_fix['LogLevel'].upper())
Exemplo n.º 6
0
  def _TsDiagnosticToYcmdDiagnostic( self, request_data, ts_diagnostic ):
    filepath = request_data[ 'filepath' ]

    ts_fixes = self._SendRequest( 'getCodeFixes', {
      'file':        filepath,
      'startLine':   ts_diagnostic[ 'startLocation' ][ 'line' ],
      'startOffset': ts_diagnostic[ 'startLocation' ][ 'offset' ],
      'endLine':     ts_diagnostic[ 'endLocation' ][ 'line' ],
      'endOffset':   ts_diagnostic[ 'endLocation' ][ 'offset' ],
      'errorCodes':  [ ts_diagnostic[ 'code' ] ]
    } )
    location = responses.Location( request_data[ 'line_num' ],
                                   request_data[ 'column_num' ],
                                   filepath )

    fixits = [ responses.FixIt( location,
                                _BuildFixItForChanges( request_data,
                                                       fix[ 'changes' ] ),
                                fix[ 'description' ] )
               for fix in ts_fixes ]

    contents = GetFileLines( request_data, filepath )

    ts_start_location = ts_diagnostic[ 'startLocation' ]
    ts_start_line = ts_start_location[ 'line' ]
    start_offset = utils.CodepointOffsetToByteOffset(
      contents[ ts_start_line - 1 ],
      ts_start_location[ 'offset' ] )

    ts_end_location = ts_diagnostic[ 'endLocation' ]
    ts_end_line = ts_end_location[ 'line' ]
    end_offset = utils.CodepointOffsetToByteOffset(
      contents[ ts_end_line - 1 ],
      ts_end_location[ 'offset' ] )

    location_start = responses.Location( ts_start_line, start_offset, filepath )
    location_end = responses.Location( ts_end_line, end_offset, filepath )

    location_extent = responses.Range( location_start, location_end )

    return responses.Diagnostic( [ location_extent ],
                                 location_start,
                                 location_extent,
                                 ts_diagnostic[ 'message' ],
                                 'ERROR',
                                 fixits = fixits )
Exemplo n.º 7
0
def TsDiagnosticToYcmdDiagnostic(filepath, line_value, ts_diagnostic):
    ts_start_location = ts_diagnostic['startLocation']
    ts_end_location = ts_diagnostic['endLocation']

    start_offset = utils.CodepointOffsetToByteOffset(
        line_value, ts_start_location['offset'])
    end_offset = utils.CodepointOffsetToByteOffset(line_value,
                                                   ts_end_location['offset'])

    location = responses.Location(ts_start_location['line'], start_offset,
                                  filepath)
    location_end = responses.Location(ts_end_location['line'], end_offset,
                                      filepath)

    location_extent = responses.Range(location, location_end)

    return responses.Diagnostic([location_extent], location, location_extent,
                                ts_diagnostic['message'], 'ERROR')
Exemplo n.º 8
0
def TsDiagnosticToYcmdDiagnostic(request_data, ts_diagnostic):
    filepath = request_data['filepath']
    contents = request_data['lines']

    ts_start_location = ts_diagnostic['startLocation']
    ts_start_line = ts_start_location['line']
    start_offset = utils.CodepointOffsetToByteOffset(
        contents[ts_start_line - 1], ts_start_location['offset'])

    ts_end_location = ts_diagnostic['endLocation']
    ts_end_line = ts_end_location['line']
    end_offset = utils.CodepointOffsetToByteOffset(contents[ts_end_line - 1],
                                                   ts_end_location['offset'])

    location_start = responses.Location(ts_start_line, start_offset, filepath)
    location_end = responses.Location(ts_end_line, end_offset, filepath)

    location_extent = responses.Range(location_start, location_end)

    return responses.Diagnostic([location_extent], location_start,
                                location_extent, ts_diagnostic['message'],
                                'ERROR')