From 182848050e412e3b46f09e928ecc23d32ae9cea1 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Fri, 10 Jan 2014 12:54:20 -0800 Subject: [PATCH] Only removing our signs in buffer, no all We used to remove all the signs in a buffer. Now we just remove the ones we set. This prevents conflicts with other Vim plugins. --- python/ycm/diagnostic_interface.py | 55 +++++++++++++++++++----------- python/ycm/vimsupport.py | 6 ++-- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/python/ycm/diagnostic_interface.py b/python/ycm/diagnostic_interface.py index f03c83ad..815add28 100644 --- a/python/ycm/diagnostic_interface.py +++ b/python/ycm/diagnostic_interface.py @@ -31,6 +31,7 @@ class DiagnosticInterface( object ): self._next_sign_id = 1 self._previous_line_number = -1 self._diag_message_needs_clearing = False + self._buffer_number_to_sign_ids = defaultdict( set ) def OnCursorMoved( self ): @@ -47,8 +48,7 @@ class DiagnosticInterface( object ): self._buffer_number_to_line_to_diags = _ConvertDiagListToDict( diags ) if self._user_options[ 'enable_diagnostic_signs' ]: - self._next_sign_id = _UpdateSigns( self._buffer_number_to_line_to_diags, - self._next_sign_id ) + self._UpdateSigns() if self._user_options[ 'enable_diagnostic_highlighting' ]: _UpdateSquiggles( self._buffer_number_to_line_to_diags ) @@ -71,6 +71,40 @@ class DiagnosticInterface( object ): self._diag_message_needs_clearing = True + def _UnplaceSignsInBuffer( self, buffer_number ): + vimsupport.UnplaceSignsInBuffer( + buffer_number, + self._buffer_number_to_sign_ids[ buffer_number ] ) + + self._buffer_number_to_sign_ids[ buffer_number ].clear() + + + def _PlaceSignInBuffer( self, line, buffer_number, is_error ): + vimsupport.PlaceSign( self._next_sign_id, + line, + buffer_number, + is_error ) + self._buffer_number_to_sign_ids[ buffer_number ].add( self._next_sign_id ) + self._next_sign_id += 1 + + + def _UpdateSigns( self ): + self._UnplaceSignsInBuffer( vim.current.buffer.number ) + + for buffer_number, line_to_diags in \ + self._buffer_number_to_line_to_diags.iteritems(): + if not vimsupport.BufferIsVisible( buffer_number ): + continue + + self._UnplaceSignsInBuffer( buffer_number ) + + for line, diags in line_to_diags.iteritems(): + for diag in diags: + self._PlaceSignInBuffer( line, + buffer_number, + _DiagnosticIsError( diag ) ) + + def _UpdateSquiggles( buffer_number_to_line_to_diags ): vimsupport.ClearYcmSyntaxMatches() line_to_diags = buffer_number_to_line_to_diags[ vim.current.buffer.number ] @@ -102,23 +136,6 @@ def _UpdateSquiggles( buffer_number_to_line_to_diags ): is_error = is_error ) -def _UpdateSigns( buffer_number_to_line_to_diags, next_sign_id ): - vimsupport.UnplaceAllSignsInBuffer( vim.current.buffer.number ) - for buffer_number, line_to_diags in buffer_number_to_line_to_diags.iteritems(): - if not vimsupport.BufferIsVisible( buffer_number ): - continue - - vimsupport.UnplaceAllSignsInBuffer( buffer_number ) - for line, diags in line_to_diags.iteritems(): - for diag in diags: - vimsupport.PlaceSign( next_sign_id, - line, - buffer_number, - _DiagnosticIsError( diag ) ) - next_sign_id += 1 - return next_sign_id - - def _ConvertDiagListToDict( diag_list ): buffer_to_line_to_diags = defaultdict( lambda: defaultdict( list ) ) for diag in diag_list: diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 9583d03c..6ad020ac 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -107,11 +107,11 @@ def GetBufferFilepath( buffer_object ): return os.path.join( os.getcwd(), str( buffer_object.number ) ) -# TODO: only unplace our signs, not all signs -def UnplaceAllSignsInBuffer( buffer_number ): +def UnplaceSignsInBuffer( buffer_number, signs ): if buffer_number < 0: return - vim.command( 'sign unplace * buffer={0}'.format( buffer_number ) ) + for sign in signs: + vim.command( 'sign unplace {0} buffer={1}'.format( sign, buffer_number ) ) def PlaceSign( sign_id, line_num, buffer_num, is_error = True ):