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:
parent
8d2ea44cb9
commit
0938d72a8c
2 changed files with 32 additions and 5 deletions
|
|
@ -35,6 +35,7 @@ class StackTraceView( object ):
|
||||||
|
|
||||||
self._threads = []
|
self._threads = []
|
||||||
self._sources = {}
|
self._sources = {}
|
||||||
|
self._scratch_buffers = []
|
||||||
|
|
||||||
utils.SetUpHiddenBuffer( self._buf, 'vimspector.StackTrace' )
|
utils.SetUpHiddenBuffer( self._buf, 'vimspector.StackTrace' )
|
||||||
|
|
||||||
|
|
@ -82,6 +83,11 @@ class StackTraceView( object ):
|
||||||
def Reset( self ):
|
def Reset( self ):
|
||||||
self.Clear()
|
self.Clear()
|
||||||
utils.CleanUpHiddenBuffer( self._buf )
|
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 ):
|
def LoadThreads( self, infer_current_frame ):
|
||||||
pending_request = False
|
pending_request = False
|
||||||
|
|
@ -290,7 +296,8 @@ class StackTraceView( object ):
|
||||||
self._logger.debug( "Received source %s: %s", buf_name, msg )
|
self._logger.debug( "Received source %s: %s", buf_name, msg )
|
||||||
|
|
||||||
buf = utils.BufferForFile( buf_name )
|
buf = utils.BufferForFile( buf_name )
|
||||||
utils.SetUpScratchBuffer( buf, buf_name )
|
self._scratch_buffers.append( buf )
|
||||||
|
utils.SetUpHiddenBuffer( buf, buf_name )
|
||||||
source[ 'path' ] = buf_name
|
source[ 'path' ] = buf_name
|
||||||
with utils.ModifiableScratchBuffer( buf ):
|
with utils.ModifiableScratchBuffer( buf ):
|
||||||
utils.SetBufferContents( buf, msg[ 'body' ][ 'content' ] )
|
utils.SetBufferContents( buf, msg[ 'body' ][ 'content' ] )
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,14 @@ def BufferForFile( file_name ):
|
||||||
return vim.buffers[ BufferNumberForFile( 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 ):
|
def OpenFileInCurrentWindow( file_name ):
|
||||||
buffer_number = BufferNumberForFile( file_name )
|
buffer_number = BufferNumberForFile( file_name )
|
||||||
try:
|
try:
|
||||||
|
|
@ -190,6 +198,18 @@ def RestoreCurrentBuffer( window ):
|
||||||
vim.current.buffer = old_buffer
|
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
|
@contextlib.contextmanager
|
||||||
def LetCurrentWindow( window ):
|
def LetCurrentWindow( window ):
|
||||||
with RestoreCurrentWindow():
|
with RestoreCurrentWindow():
|
||||||
|
|
@ -566,11 +586,11 @@ def SetSyntax( current_syntax, syntax, *args ):
|
||||||
if current_syntax == syntax:
|
if current_syntax == syntax:
|
||||||
return
|
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:
|
for buf in args:
|
||||||
with LetCurrentBuffer( buf ):
|
with AnyWindowForBuffer( 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
|
|
||||||
vim.command( 'set syntax={}'.format( Escape( syntax ) ) )
|
vim.command( 'set syntax={}'.format( Escape( syntax ) ) )
|
||||||
|
|
||||||
return syntax
|
return syntax
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue