From def392d24c7b4b34c0e8b95c400c9be94176b928 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Wed, 29 Oct 2014 10:16:38 -0700 Subject: [PATCH] Fix Vim E885: not possible to change sign Clang will sometimes give a diagnostic for line 0, and Vim borks on placing signs for line 0. --- python/ycm/diagnostic_interface.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/python/ycm/diagnostic_interface.py b/python/ycm/diagnostic_interface.py index 79b9dcb3..62c1db22 100644 --- a/python/ycm/diagnostic_interface.py +++ b/python/ycm/diagnostic_interface.py @@ -45,7 +45,9 @@ class DiagnosticInterface( object ): def UpdateWithNewDiagnostics( self, diags ): - self._buffer_number_to_line_to_diags = _ConvertDiagListToDict( diags ) + normalized_diags = [ _NormalizeDiagnostic( x ) for x in diags ] + self._buffer_number_to_line_to_diags = _ConvertDiagListToDict( + normalized_diags ) if self._user_options[ 'enable_diagnostic_signs' ]: self._placed_signs, self._next_sign_id = _UpdateSigns( @@ -58,7 +60,7 @@ class DiagnosticInterface( object ): if self._user_options[ 'always_populate_location_list' ]: vimsupport.SetLocationList( - vimsupport.ConvertDiagnosticsToQfList( diags ) ) + vimsupport.ConvertDiagnosticsToQfList( normalized_diags ) ) def _EchoDiagnosticForLine( self, line_num ): @@ -204,6 +206,16 @@ def _DiagnosticIsError( diag ): return diag[ 'kind' ] == 'ERROR' +def _NormalizeDiagnostic( diag ): + def ClampToOne( value ): + return value if value > 0 else 1 + + location = diag[ 'location' ] + location[ 'column_num' ] = ClampToOne( location[ 'column_num' ] ) + location[ 'line_num' ] = ClampToOne( location[ 'line_num' ] ) + return diag + + class _DiagSignPlacement( namedtuple( "_DiagSignPlacement", [ 'id', 'line', 'buffer', 'is_error' ] ) ): # We want two signs that have different ids but the same location to compare