diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index cca72940..be8ee338 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -671,9 +671,10 @@ def CheckFilename( filename ): "filename '{0}' cannot be opened. {1}".format( filename, error ) ) -def BufferExistsForFilename( filename ): +def BufferIsVisibleForFilename( filename ): """Check if a buffer exists for a specific file.""" - return GetBufferNumberForFilename( filename, False ) is not -1 + buffer_number = GetBufferNumberForFilename( filename, False ) + return BufferIsVisible( buffer_number ) def CloseBuffersForFilename( filename ): @@ -681,7 +682,11 @@ def CloseBuffersForFilename( filename ): buffer_number = GetBufferNumberForFilename( filename, False ) while buffer_number is not -1: vim.command( 'silent! bwipeout! {0}'.format( buffer_number ) ) - buffer_number = GetBufferNumberForFilename( filename, False ) + new_buffer_number = GetBufferNumberForFilename( filename, False ) + if buffer_number == new_buffer_number: + raise RuntimeError( "Buffer {0} for filename '{1}' should already be " + "wiped out.".format( buffer_number, filename ) ) + buffer_number = new_buffer_number def OpenFilename( filename, options = {} ): diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 0df4a1d4..77b81a0a 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -534,11 +534,14 @@ class YouCompleteMe( object ): def ToggleLogs( self, stdout = True, stderr = True ): if ( stdout and - vimsupport.BufferExistsForFilename( self._server_stdout ) or + vimsupport.BufferIsVisibleForFilename( self._server_stdout ) or stderr and - vimsupport.BufferExistsForFilename( self._server_stderr ) ): + vimsupport.BufferIsVisibleForFilename( self._server_stderr ) ): return self._CloseLogs( stdout = stdout, stderr = stderr ) + # Close hidden logfile buffers if any to keep a clean state + self._CloseLogs( stdout = stdout, stderr = stderr ) + try: self._OpenLogs( stdout = stdout, stderr = stderr ) except RuntimeError as error: