Re-use a window if we can, as it's more efficient; don't wipe out the generated code buffers in case the code window gets used for temporary buffer switch

This commit is contained in:
Ben Jackson 2020-07-11 22:00:36 +01:00
commit 0938d72a8c
2 changed files with 32 additions and 5 deletions

View file

@ -35,6 +35,7 @@ class StackTraceView( object ):
self._threads = []
self._sources = {}
self._scratch_buffers = []
utils.SetUpHiddenBuffer( self._buf, 'vimspector.StackTrace' )
@ -82,6 +83,11 @@ class StackTraceView( object ):
def Reset( self ):
self.Clear()
utils.CleanUpHiddenBuffer( self._buf )
for b in self._scratch_buffers:
utils.CleanUpHiddenBuffer( b )
self._scratch_buffers = []
self._buf = None
def LoadThreads( self, infer_current_frame ):
pending_request = False
@ -290,7 +296,8 @@ class StackTraceView( object ):
self._logger.debug( "Received source %s: %s", buf_name, msg )
buf = utils.BufferForFile( buf_name )
utils.SetUpScratchBuffer( buf, buf_name )
self._scratch_buffers.append( buf )
utils.SetUpHiddenBuffer( buf, buf_name )
source[ 'path' ] = buf_name
with utils.ModifiableScratchBuffer( buf ):
utils.SetBufferContents( buf, msg[ 'body' ][ 'content' ] )

View file

@ -52,6 +52,14 @@ def BufferForFile( file_name ):
return vim.buffers[ BufferNumberForFile( file_name ) ]
def WindowForBuffer( buf ):
for w in vim.current.tabpage.windows:
if w.buffer == buf:
return w
return None
def OpenFileInCurrentWindow( file_name ):
buffer_number = BufferNumberForFile( file_name )
try:
@ -190,6 +198,18 @@ def RestoreCurrentBuffer( window ):
vim.current.buffer = old_buffer
@contextlib.contextmanager
def AnyWindowForBuffer( buf ):
# Only checks the current tab page, which is what we want
current_win = WindowForBuffer( buf )
if current_win is not None:
with LetCurrentWindow( current_win ):
yield
else:
with LetCurrentBuffer( buf ):
yield
@contextlib.contextmanager
def LetCurrentWindow( window ):
with RestoreCurrentWindow():
@ -566,11 +586,11 @@ def SetSyntax( current_syntax, syntax, *args ):
if current_syntax == syntax:
return
# We use set syn= because just setting vim.Buffer.options[ 'syntax' ]
# doesn't actually trigger the Syntax autocommand, and i'm not sure that
# 'doautocmd Syntax' is the right solution or not
for buf in args:
with LetCurrentBuffer( buf ):
# We use set syn= because just setting vim.Buffer.options[ 'syntax' ]
# doesn't actually trigger the Syntax autocommand, and i'm not sure that
# 'doautocmd Syntax' is the right solution or not
with AnyWindowForBuffer( buf ):
vim.command( 'set syntax={}'.format( Escape( syntax ) ) )
return syntax