Improve :YcmToggleLogs behavior

If already opened logfiles are not visible (hidden buffers or in another
tab), close them and open new ones. It fixes the issue where the command
seems to do nothing even though it actually close the non-visible logfiles.
This commit is contained in:
micbou 2015-11-11 14:32:01 +01:00
parent 2eb75ced81
commit 6f36c3ff82
2 changed files with 13 additions and 5 deletions

View File

@ -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 = {} ):

View File

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