Use a prompt buffer for adding watches
This very new feature makes it kind of nice to add new watches in the place where they will appear, keeping the eye in the same screen location.
This commit is contained in:
parent
b9ceb5e8ec
commit
920db068c6
7 changed files with 54 additions and 9 deletions
|
|
@ -48,7 +48,7 @@ class StackTraceView( object ):
|
|||
self._currentThread = None
|
||||
self._threads = []
|
||||
with utils.ModifiableScratchBuffer( self._buf ):
|
||||
self._buf[:] = None
|
||||
utils.ClearBuffer( self._buf )
|
||||
|
||||
def ConnectionClosed( self ):
|
||||
self.Clear()
|
||||
|
|
@ -88,7 +88,7 @@ class StackTraceView( object ):
|
|||
self._line_to_thread.clear()
|
||||
|
||||
with utils.ModifiableScratchBuffer( self._buf ):
|
||||
self._buf[:] = None
|
||||
utils.ClearBuffer( self._buf )
|
||||
|
||||
for thread in self._threads:
|
||||
icon = '+' if '_frames' not in thread else '-'
|
||||
|
|
|
|||
|
|
@ -52,9 +52,34 @@ def SetUpHiddenBuffer( buf, name ):
|
|||
buf.options[ 'bufhidden' ] = 'hide'
|
||||
buf.name = name
|
||||
|
||||
def SetUpPromptBuffer( buf, name, prompt, callback ):
|
||||
# This feature is _super_ new, so only enable when available
|
||||
if not int( vim.eval( "exists( '*prompt_setprompt' )" ) ):
|
||||
return SetUpScratchBuffer( buf, name )
|
||||
|
||||
buf.options[ 'buftype' ] = 'prompt'
|
||||
buf.options[ 'swapfile' ] = False
|
||||
buf.options[ 'modifiable' ] = True
|
||||
buf.options[ 'modified' ] = False
|
||||
buf.options[ 'readonly' ] = False
|
||||
buf.options[ 'buflisted' ] = False
|
||||
buf.options[ 'bufhidden' ] = 'wipe'
|
||||
buf.name = name
|
||||
|
||||
vim.eval( "prompt_setprompt( {0}, '{1}' )".format( buf.number,
|
||||
Escape( prompt ) ) )
|
||||
vim.eval( "prompt_setcallback( {0}, function( '{1}' ) )".format(
|
||||
buf.number,
|
||||
Escape( callback ) ) )
|
||||
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def ModifiableScratchBuffer( buf ):
|
||||
if buf.options[ 'modifiable' ]:
|
||||
yield
|
||||
return
|
||||
|
||||
buf.options[ 'modifiable' ] = True
|
||||
buf.options[ 'readonly' ] = False
|
||||
try:
|
||||
|
|
@ -189,3 +214,7 @@ def AppendToBuffer( buf, line_or_lines ):
|
|||
|
||||
# Return the first Vim line number (1-based) that we just set.
|
||||
return line
|
||||
|
||||
|
||||
def ClearBuffer( buf ):
|
||||
buf[:] = None
|
||||
|
|
|
|||
|
|
@ -60,7 +60,10 @@ class VariablesView( object ):
|
|||
'nnoremap <buffer> <DEL> :call vimspector#DeleteWatch()<CR>' )
|
||||
|
||||
utils.SetUpScratchBuffer( self._vars.win.buffer, 'vimspector.Variables' )
|
||||
utils.SetUpScratchBuffer( self._watch.win.buffer, 'vimspector.Watches' )
|
||||
utils.SetUpPromptBuffer( self._watch.win.buffer,
|
||||
'vimspector.Watches',
|
||||
'Watch: ',
|
||||
'vimspector#AddWatchPrompt' )
|
||||
|
||||
has_balloon = int( vim.eval( "has( 'balloon_eval' )" ) )
|
||||
has_balloon_term = int( vim.eval( "has( 'balloon_eval_term' )" ) )
|
||||
|
|
@ -85,9 +88,9 @@ class VariablesView( object ):
|
|||
|
||||
def Clear( self ):
|
||||
with utils.ModifiableScratchBuffer( self._vars.win.buffer ):
|
||||
self._vars.win.buffer[:] = None
|
||||
utils.ClearBuffer( self._vars.win.buffer )
|
||||
with utils.ModifiableScratchBuffer( self._watch.win.buffer ):
|
||||
self._watch.win.buffer[:] = None
|
||||
utils.ClearBuffer( self._watch.win.buffer )
|
||||
|
||||
def ConnectionClosed( self ):
|
||||
self.Clear()
|
||||
|
|
@ -251,7 +254,7 @@ class VariablesView( object ):
|
|||
self._vars.lines.clear()
|
||||
with utils.RestoreCursorPosition():
|
||||
with utils.ModifiableScratchBuffer( self._vars.win.buffer ):
|
||||
self._vars.win.buffer[:] = None
|
||||
utils.ClearBuffer( self._vars.win.buffer )
|
||||
for scope in self._scopes:
|
||||
self._DrawScope( 0, scope )
|
||||
|
||||
|
|
@ -263,7 +266,7 @@ class VariablesView( object ):
|
|||
self._watch.lines.clear()
|
||||
with utils.RestoreCursorPosition():
|
||||
with utils.ModifiableScratchBuffer( self._watch.win.buffer ):
|
||||
self._watch.win.buffer[:] = None
|
||||
utils.ClearBuffer( self._watch.win.buffer )
|
||||
utils.AppendToBuffer( self._watch.win.buffer, 'Watches: ----' )
|
||||
for watch in self._watches:
|
||||
line = utils.AppendToBuffer( self._watch.win.buffer,
|
||||
|
|
@ -297,8 +300,7 @@ class VariablesView( object ):
|
|||
line = '{0}{1} Result: {2} '.format( ' ' * indent,
|
||||
icon,
|
||||
result[ 'result' ] )
|
||||
line = utils.AppendToBuffer( self._watch.win.buffer,
|
||||
line.split( '\n' ) )
|
||||
line = utils.AppendToBuffer( self._watch.win.buffer, line.split( '\n' ) )
|
||||
self._watch.lines[ line ] = result
|
||||
|
||||
if '_variables' in result:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue