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.
This commit is contained in:
Strahinja Val Markovic 2014-01-10 12:54:20 -08:00
parent 8866f798b6
commit 182848050e
2 changed files with 39 additions and 22 deletions

View File

@ -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:

View File

@ -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 ):