Tidy up, refactor and fix some bugs

This commit is contained in:
Ben Jackson 2021-02-21 00:34:51 +00:00
commit cc84e15932
6 changed files with 307 additions and 210 deletions

View file

@ -520,8 +520,8 @@ class DebugSession( object ):
self._stackTraceView.SetCurrentThread()
@IfConnected()
def ExpandVariable( self, lineNum = -1 ):
self._variablesView.ExpandVariable( lineNum )
def ExpandVariable( self, buf = None, line_num = None ):
self._variablesView.ExpandVariable( buf, line_num )
@IfConnected()
def AddWatch( self, expression ):
@ -558,8 +558,8 @@ class DebugSession( object ):
return self._variablesView.VariableEval( frame, expression, is_hover )
def _CleanUpTooltip( self ):
return self._variablesView._CleanUpTooltip()
def CleanUpTooltip( self ):
return self._variablesView.CleanUpTooltip()
@IfConnected()
def ExpandFrameOrThread( self ):

View file

@ -645,8 +645,6 @@ def DisplayBalloon( is_term, display, is_hover = False ):
)
) )
vim.eval( "vimspector#internal#balloon#nvim_resize_tooltip()" )
return created_win_id
@ -728,11 +726,20 @@ def GetVisualSelection( bufnr ):
start_line, start_col = vim.current.buffer.mark( "<" )
end_line, end_col = vim.current.buffer.mark( ">" )
# lines are 1 based, but columns are 0 based
# don't as me why...
lines = vim.buffers[ bufnr ][ start_line - 1 : end_line ]
lines[ 0 ] = lines[ 0 ][ start_col : ]
# don't ask me why...
start_line -= 1
end_line -= 1
lines = vim.buffers[ bufnr ][ start_line : end_line + 1 ]
# Do end first, in case it's on the same line as start (as doing start first
# would change the offset)
lines[ -1 ] = lines[ -1 ][ : end_col + 1 ]
lines[ 0 ] = lines[ 0 ][ start_col : ]
_logger.debug( f'Visual selection: { lines } from '
f'{ start_line }/{ start_col } -> { end_line }/{ end_col }' )
return lines

View file

@ -143,6 +143,12 @@ class View:
utils.SetUpUIWindow( win )
class BufView( View ):
def __init__( self, buf, lines, draw ):
super().__init__( None, lines, draw )
self.buf = buf
class VariablesView( object ):
def __init__( self, variables_win, watches_win ):
self._logger = logging.getLogger( __name__ )
@ -219,6 +225,7 @@ class VariablesView( object ):
utils.ClearBuffer( self._vars.buf )
with utils.ModifiableScratchBuffer( self._watch.buf ):
utils.ClearBuffer( self._watch.buf )
self.ClearTooltip()
self._current_syntax = ''
def ConnectionUp( self, connection ):
@ -234,6 +241,8 @@ class VariablesView( object ):
utils.CleanUpHiddenBuffer( self._vars.buf )
utils.CleanUpHiddenBuffer( self._watch.buf )
self.ClearTooltip()
def LoadScopes( self, frame ):
def scopes_consumer( message ):
@ -302,9 +311,14 @@ class VariablesView( object ):
watch,
is_short = True )
vim.eval( "vimspector#internal#balloon#nvim_resize_tooltip()" )
vim.eval( "vimspector#internal#balloon#ResizeTooltip()" )
def _CleanUpTooltip( self ) :
def ClearTooltip( self ):
# This will actually end up calling CleanUpTooltip via the popup close
# callback
vim.eval( 'vimspector#internal#balloon#Close()' )
def CleanUpTooltip( self ) :
# remove reference to old tooltip window
self._variable_eval_view = None
vim.vars[ 'vimspector_session_windows' ][ 'eval' ] = None
@ -322,22 +336,17 @@ class VariablesView( object ):
else:
watch.result.Update( message[ 'body' ] )
float_win_id = utils.DisplayBalloon( self._is_term, [], is_hover )
popup_win_id = utils.DisplayBalloon( self._is_term, [], is_hover )
# record the global eval window id
vim.vars[ 'vimspector_session_windows' ][ 'eval' ] = int( float_win_id )
float_buf_nr = int( vim.eval( "winbufnr({})".format( float_win_id ) ) )
vim.vars[ 'vimspector_session_windows' ][ 'eval' ] = int( popup_win_id )
popup_bufnr = int( vim.eval( "winbufnr({})".format( popup_win_id ) ) )
# since vim's popup cant be focused there is no way
# to get a reference to its window
# we will emulate python's window object ourselves
self._variable_eval_view = View(
type(
'__vim__window__',
( object, ),
{ 'options': {}, 'buffer': vim.buffers[ float_buf_nr ] }
),
{},
self._DrawBalloonEval
# We don't need to do any UI window setup here, as it's already done as
# part of the popup creation, so just pass the buffer to the View instance
self._variable_eval_view = BufView(
vim.buffers[ popup_bufnr ],
{},
self._DrawBalloonEval
)
if watch.result.IsExpandable():
@ -439,21 +448,27 @@ class VariablesView( object ):
watch.result = WatchFailure( reason )
self._DrawWatches()
def ExpandVariable( self, lineNum = -1 ):
if vim.current.buffer == self._vars.buf:
def ExpandVariable( self, buf = None, line_num = None ):
if buf is None:
buf = vim.current.buffer
if line_num is None:
line_num = vim.current.window.cursor[ 0 ]
if buf == self._vars.buf:
view = self._vars
elif vim.current.buffer == self._watch.buf:
elif buf == self._watch.buf:
view = self._watch
elif self._variable_eval_view is not None:
elif ( self._variable_eval_view is not None
and buf == self._variable_eval_view.buf ):
view = self._variable_eval_view
else:
return
current_line = vim.current.window.cursor[ 0 ] if lineNum <= 0 else lineNum
if current_line not in view.lines:
if line_num not in view.lines:
return
variable = view.lines[ current_line ]
variable = view.lines[ line_num ]
if variable.IsExpanded():
# Collapse