Don't leak buffers when creating output view
This commit is contained in:
parent
18fd56484e
commit
f538102d33
2 changed files with 121 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ from vimspector import utils, install
|
||||||
|
|
||||||
import vim
|
import vim
|
||||||
import json
|
import json
|
||||||
|
import typing
|
||||||
|
|
||||||
|
|
||||||
class TabBuffer( object ):
|
class TabBuffer( object ):
|
||||||
|
|
@ -55,6 +56,8 @@ def ShowOutputInWindow( win_id, category ):
|
||||||
class OutputView( object ):
|
class OutputView( object ):
|
||||||
"""Container for a 'tabbed' window of buffers that can be used to display
|
"""Container for a 'tabbed' window of buffers that can be used to display
|
||||||
files or the output of commands."""
|
files or the output of commands."""
|
||||||
|
_buffers: typing.Dict[ str, TabBuffer ]
|
||||||
|
|
||||||
def __init__( self, window, api_prefix ):
|
def __init__( self, window, api_prefix ):
|
||||||
self._window = window
|
self._window = window
|
||||||
self._buffers = {}
|
self._buffers = {}
|
||||||
|
|
@ -146,6 +149,17 @@ class OutputView( object ):
|
||||||
cmd = None,
|
cmd = None,
|
||||||
completion_handler = None,
|
completion_handler = None,
|
||||||
syntax = 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:
|
if file_name is not None:
|
||||||
assert cmd is None
|
assert cmd is None
|
||||||
if install.GetOS() == "windows":
|
if install.GetOS() == "windows":
|
||||||
|
|
@ -160,6 +174,7 @@ class OutputView( object ):
|
||||||
category,
|
category,
|
||||||
self._api_prefix,
|
self._api_prefix,
|
||||||
completion_handler = completion_handler )
|
completion_handler = completion_handler )
|
||||||
|
|
||||||
self._buffers[ category ] = TabBuffer( out, len( self._buffers ) )
|
self._buffers[ category ] = TabBuffer( out, len( self._buffers ) )
|
||||||
self._buffers[ category ].is_job = True
|
self._buffers[ category ].is_job = True
|
||||||
self._RenderWinBar( category )
|
self._RenderWinBar( category )
|
||||||
|
|
@ -170,6 +185,7 @@ class OutputView( object ):
|
||||||
name = 'vimspector.Output:{0}'.format( category )
|
name = 'vimspector.Output:{0}'.format( category )
|
||||||
|
|
||||||
tab_buffer = TabBuffer( utils.NewEmptyBuffer(), len( self._buffers ) )
|
tab_buffer = TabBuffer( utils.NewEmptyBuffer(), len( self._buffers ) )
|
||||||
|
|
||||||
self._buffers[ category ] = tab_buffer
|
self._buffers[ category ] = tab_buffer
|
||||||
|
|
||||||
if category == 'Console':
|
if category == 'Console':
|
||||||
|
|
@ -187,6 +203,11 @@ class OutputView( object ):
|
||||||
syntax,
|
syntax,
|
||||||
self._buffers[ category ].buf )
|
self._buffers[ category ].buf )
|
||||||
|
|
||||||
|
if buf_to_delete:
|
||||||
|
with utils.RestoreCurrentWindow():
|
||||||
|
self._ShowOutput( category )
|
||||||
|
utils.CleanUpHiddenBuffer( buf_to_delete )
|
||||||
|
|
||||||
def _RenderWinBar( self, category ):
|
def _RenderWinBar( self, category ):
|
||||||
if not self._window.valid:
|
if not self._window.valid:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -49,3 +49,103 @@ function! Test_Step_With_Different_Tabpage()
|
||||||
%bwipeout!
|
%bwipeout!
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! Test_All_Buffers_Deleted_NoHidden()
|
||||||
|
set nohidden
|
||||||
|
lcd testdata/cpp/simple
|
||||||
|
edit simple.cpp
|
||||||
|
|
||||||
|
let opts = #{ buflisted: v:true }
|
||||||
|
|
||||||
|
let buffers_before = getbufinfo( opts )
|
||||||
|
|
||||||
|
call setpos( '.', [ 0, 15, 1 ] )
|
||||||
|
call vimspector#ToggleBreakpoint()
|
||||||
|
call vimspector#Launch()
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
||||||
|
call vimspector#test#signs#AssertPCIsAtLineInBuffer(
|
||||||
|
\ 'simple.cpp',
|
||||||
|
\ 15 )
|
||||||
|
|
||||||
|
call vimspector#Reset()
|
||||||
|
call vimspector#test#setup#WaitForReset()
|
||||||
|
|
||||||
|
let buffers_after = getbufinfo( opts )
|
||||||
|
|
||||||
|
call assert_equal( len( buffers_before ), len( buffers_after ) )
|
||||||
|
|
||||||
|
set hidden&
|
||||||
|
lcd -
|
||||||
|
call vimspector#test#setup#Reset()
|
||||||
|
%bwipe!
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! Test_All_Buffers_Deleted_Hidden()
|
||||||
|
set hidden
|
||||||
|
lcd testdata/cpp/simple
|
||||||
|
edit simple.cpp
|
||||||
|
|
||||||
|
let opts = #{ buflisted: v:true }
|
||||||
|
|
||||||
|
let buffers_before = getbufinfo( opts )
|
||||||
|
|
||||||
|
call setpos( '.', [ 0, 15, 1 ] )
|
||||||
|
call vimspector#ToggleBreakpoint()
|
||||||
|
call vimspector#Launch()
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
|
||||||
|
call vimspector#test#signs#AssertPCIsAtLineInBuffer(
|
||||||
|
\ 'simple.cpp',
|
||||||
|
\ 15 )
|
||||||
|
|
||||||
|
call vimspector#Reset()
|
||||||
|
call vimspector#test#setup#WaitForReset()
|
||||||
|
|
||||||
|
let buffers_after = getbufinfo( opts )
|
||||||
|
|
||||||
|
call assert_equal( len( buffers_before ), len( buffers_after ) )
|
||||||
|
|
||||||
|
set hidden&
|
||||||
|
lcd -
|
||||||
|
call vimspector#test#setup#Reset()
|
||||||
|
%bwipe!
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! Test_All_Buffers_Deleted_ToggleLog()
|
||||||
|
set hidden
|
||||||
|
let buffers_before = getbufinfo( #{ buflisted: 1 } )
|
||||||
|
VimspectorToggleLog
|
||||||
|
VimspectorToggleLog
|
||||||
|
let buffers_after = getbufinfo( #{ buflisted: 1 } )
|
||||||
|
call assert_equal( len( buffers_before ), len( buffers_after ) )
|
||||||
|
|
||||||
|
call vimspector#test#setup#Reset()
|
||||||
|
set hidden&
|
||||||
|
%bwipe!
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let g:vimspector_test_install_done = 0
|
||||||
|
|
||||||
|
function! Test_All_Buffers_Deleted_Installer()
|
||||||
|
set hidden
|
||||||
|
let buffers_before = getbufinfo( #{ buflisted: 1 } )
|
||||||
|
|
||||||
|
augroup Test_All_Buffers_Deleted_Installer
|
||||||
|
au!
|
||||||
|
au User VimspectorInstallSuccess let g:vimspector_test_install_done = 1
|
||||||
|
au User VimspectorInstallFailed let g:vimspector_test_install_done = 1
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
VimspectorUpdate
|
||||||
|
|
||||||
|
" The test timeout will take care of this taking too long
|
||||||
|
call WaitForAssert(
|
||||||
|
\ { -> assert_equal( 1, g:vimspector_test_install_done ) },
|
||||||
|
\ 120000 )
|
||||||
|
|
||||||
|
let buffers_after = getbufinfo( #{ buflisted: 1 } )
|
||||||
|
call assert_equal( len( buffers_before ), len( buffers_after ) )
|
||||||
|
|
||||||
|
call vimspector#test#setup#Reset()
|
||||||
|
set hidden&
|
||||||
|
au! Test_All_Buffers_Deleted_Installer
|
||||||
|
%bwipe!
|
||||||
|
endfunction
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue