Don't leak buffers when creating output view

This commit is contained in:
Ben Jackson 2020-09-01 15:01:24 +01:00
commit f538102d33
2 changed files with 121 additions and 0 deletions

View file

@ -17,6 +17,7 @@ from vimspector import utils, install
import vim
import json
import typing
class TabBuffer( object ):
@ -55,6 +56,8 @@ def ShowOutputInWindow( win_id, category ):
class OutputView( object ):
"""Container for a 'tabbed' window of buffers that can be used to display
files or the output of commands."""
_buffers: typing.Dict[ str, TabBuffer ]
def __init__( self, window, api_prefix ):
self._window = window
self._buffers = {}
@ -146,6 +149,17 @@ class OutputView( object ):
cmd = None,
completion_handler = None,
syntax = None ):
buf_to_delete = None
if ( not self._buffers
and self._window is not None
and self._window.valid
and not self._window.buffer.name ):
# If there's an empty buffer in the current window that we're not using,
# delete it. We could try and use it, but that complicates the call to
# SetUpCommandBuffer
buf_to_delete = self._window.buffer
if file_name is not None:
assert cmd is None
if install.GetOS() == "windows":
@ -160,6 +174,7 @@ class OutputView( object ):
category,
self._api_prefix,
completion_handler = completion_handler )
self._buffers[ category ] = TabBuffer( out, len( self._buffers ) )
self._buffers[ category ].is_job = True
self._RenderWinBar( category )
@ -170,6 +185,7 @@ class OutputView( object ):
name = 'vimspector.Output:{0}'.format( category )
tab_buffer = TabBuffer( utils.NewEmptyBuffer(), len( self._buffers ) )
self._buffers[ category ] = tab_buffer
if category == 'Console':
@ -187,6 +203,11 @@ class OutputView( object ):
syntax,
self._buffers[ category ].buf )
if buf_to_delete:
with utils.RestoreCurrentWindow():
self._ShowOutput( category )
utils.CleanUpHiddenBuffer( buf_to_delete )
def _RenderWinBar( self, category ):
if not self._window.valid:
return