Ejemplo n.º 1
0
 def UpdateWithNewDiagnosticsForFile( self, filepath, diagnostics ):
   bufnr = vimsupport.GetBufferNumberForFilename( filepath )
   if bufnr in self._buffers and vimsupport.BufferIsVisible( bufnr ):
     # Note: We only update location lists, etc. for visible buffers, because
     # otherwise we default to using the current location list and the results
     # are that non-visible buffer errors clobber visible ones.
     self._buffers[ bufnr ].UpdateWithNewDiagnostics( diagnostics )
   else:
     # The project contains errors in file "filepath", but that file is not
     # open in any buffer. This happens for Language Server Protocol-based
     # completers, as they return diagnostics for the entire "project"
     # asynchronously (rather than per-file in the response to the parse
     # request).
     #
     # There are a number of possible approaches for
     # this, but for now we simply ignore them. Other options include:
     # - Use the QuickFix list to report project errors?
     # - Use a special buffer for project errors
     # - Put them in the location list of whatever the "current" buffer is
     # - Store them in case the buffer is opened later
     # - add a :YcmProjectDiags command
     # - Add them to errror/warning _counts_ but not any actual location list
     #   or other
     # - etc.
     #
     # However, none of those options are great, and lead to their own
     # complexities. So for now, we just ignore these diagnostics for files not
     # open in any buffer.
     pass
Ejemplo n.º 2
0
def _ConvertDiagnosticDataToVimData(diagnostic):
    # see :h getqflist for a description of the dictionary fields
    # Note that, as usual, Vim is completely inconsistent about whether
    # line/column numbers are 1 or 0 based in its various APIs. Here, it wants
    # them to be 1-based.
    return {
        'bufnr': vimsupport.GetBufferNumberForFilename(diagnostic['filepath']),
        'lnum': diagnostic['line_num'] + 1,
        'col': diagnostic['column_num'] + 1,
        'text': diagnostic['text'],
        'type': diagnostic['kind'],
        'valid': 1
    }
Ejemplo n.º 3
0
    def _ConvertDiagListToDict(self):
        self._line_to_diags = defaultdict(list)
        for diag in self._diagnostics:
            location = diag['location']
            bufnr = vimsupport.GetBufferNumberForFilename(location['filepath'])
            if bufnr == self._bufnr:
                line_number = location['line_num']
                self._line_to_diags[line_number].append(diag)

        for diags in itervalues(self._line_to_diags):
            # We also want errors to be listed before warnings so that errors aren't
            # hidden by the warnings; Vim won't place a sign over an existing one.
            diags.sort(key=lambda diag:
                       (diag['kind'], diag['location']['column_num']))
Ejemplo n.º 4
0
def _ConvertDiagListToDict(diag_list):
    buffer_to_line_to_diags = defaultdict(lambda: defaultdict(list))
    for diag in diag_list:
        location = diag['location']
        buffer_number = vimsupport.GetBufferNumberForFilename(
            location['filepath'])
        line_number = location['line_num']
        buffer_to_line_to_diags[buffer_number][line_number].append(diag)

    for line_to_diags in itervalues(buffer_to_line_to_diags):
        for diags in itervalues(line_to_diags):
            # We also want errors to be listed before warnings so that errors aren't
            # hidden by the warnings; Vim won't place a sign oven an existing one.
            diags.sort(key=lambda diag:
                       (diag['location']['column_num'], diag['kind']))
    return buffer_to_line_to_diags