Only expand one cheap scope by default - don't keep others expanded from previous frames
This commit is contained in:
parent
fc7725fefb
commit
434a6f41d4
1 changed files with 23 additions and 18 deletions
|
|
@ -23,6 +23,11 @@ from vimspector import utils
|
||||||
|
|
||||||
|
|
||||||
class Expandable:
|
class Expandable:
|
||||||
|
EXPANDED_BY_USER = 2
|
||||||
|
EXPANDED_BY_US = 1
|
||||||
|
COLLAPSED_BY_USER = 0
|
||||||
|
COLLAPSED_BY_DEFAULT = None
|
||||||
|
|
||||||
"""Base for anything which might contain a hierarchy of values represented by
|
"""Base for anything which might contain a hierarchy of values represented by
|
||||||
a 'variablesReference' to be resolved by the 'variables' request. Records the
|
a 'variablesReference' to be resolved by the 'variables' request. Records the
|
||||||
current state expanded/collapsed. Implementations just implement
|
current state expanded/collapsed. Implementations just implement
|
||||||
|
|
@ -32,16 +37,13 @@ class Expandable:
|
||||||
# None is Falsy and represents collapsed _by default_. WHen set to False,
|
# None is Falsy and represents collapsed _by default_. WHen set to False,
|
||||||
# this means the user explicitly collapsed it. When True, the user expanded
|
# this means the user explicitly collapsed it. When True, the user expanded
|
||||||
# it (or we expanded it by default).
|
# it (or we expanded it by default).
|
||||||
self.expanded: bool = None
|
self.expanded: int = Expandable.COLLAPSED_BY_DEFAULT
|
||||||
|
|
||||||
def IsCollapsedByUser( self ):
|
def IsExpanded( self ):
|
||||||
return self.expanded is False
|
return bool( self.expanded )
|
||||||
|
|
||||||
def IsExpandedByUser( self ):
|
|
||||||
return self.expanded is True
|
|
||||||
|
|
||||||
def ShouldDrawDrillDown( self ):
|
def ShouldDrawDrillDown( self ):
|
||||||
return self.IsExpandedByUser() and self.variables is not None
|
return self.IsExpanded() and self.variables is not None
|
||||||
|
|
||||||
def IsExpandable( self ):
|
def IsExpandable( self ):
|
||||||
return self.VariablesReference() > 0
|
return self.VariablesReference() > 0
|
||||||
|
|
@ -225,11 +227,14 @@ class VariablesView( object ):
|
||||||
# Expand the first non-expensive scope which is not manually collapsed
|
# Expand the first non-expensive scope which is not manually collapsed
|
||||||
if ( not expanded_some_scope
|
if ( not expanded_some_scope
|
||||||
and not scope.scope.get( 'expensive' )
|
and not scope.scope.get( 'expensive' )
|
||||||
and not scope.IsCollapsedByUser() ):
|
and scope.expanded is not Expandable.COLLAPSED_BY_USER ):
|
||||||
scope.expanded = True
|
scope.expanded = Expandable.EXPANDED_BY_US
|
||||||
expanded_some_scope = True
|
expanded_some_scope = True
|
||||||
|
elif ( expanded_some_scope and scope.expanded is
|
||||||
|
Expandable.EXPANDED_BY_US ):
|
||||||
|
scope.expanded = Expandable.COLLAPSED_BY_DEFAULT
|
||||||
|
|
||||||
if scope.IsExpandedByUser():
|
if scope.IsExpanded():
|
||||||
self._connection.DoRequest( partial( self._ConsumeVariables,
|
self._connection.DoRequest( partial( self._ConsumeVariables,
|
||||||
self._DrawScopes,
|
self._DrawScopes,
|
||||||
scope ), {
|
scope ), {
|
||||||
|
|
@ -297,7 +302,7 @@ class VariablesView( object ):
|
||||||
watch.result = WatchResult( message[ 'body' ] )
|
watch.result = WatchResult( message[ 'body' ] )
|
||||||
|
|
||||||
if ( watch.result.IsExpandable() and
|
if ( watch.result.IsExpandable() and
|
||||||
watch.result.IsExpandedByUser() ):
|
watch.result.IsExpanded() ):
|
||||||
self._connection.DoRequest( partial( self._ConsumeVariables,
|
self._connection.DoRequest( partial( self._ConsumeVariables,
|
||||||
self._watch.draw,
|
self._watch.draw,
|
||||||
watch.result ), {
|
watch.result ), {
|
||||||
|
|
@ -323,16 +328,16 @@ class VariablesView( object ):
|
||||||
|
|
||||||
variable = view.lines[ current_line ]
|
variable = view.lines[ current_line ]
|
||||||
|
|
||||||
if variable.expanded:
|
if variable.IsExpanded():
|
||||||
# Collapse
|
# Collapse
|
||||||
variable.expanded = False
|
variable.expanded = Expandable.COLLAPSED_BY_USER
|
||||||
view.draw()
|
view.draw()
|
||||||
return
|
return
|
||||||
|
|
||||||
if not variable.IsExpandable():
|
if not variable.IsExpandable():
|
||||||
return
|
return
|
||||||
|
|
||||||
variable.expanded = True
|
variable.expanded = Expandable.EXPANDED_BY_USER
|
||||||
self._connection.DoRequest( partial( self._ConsumeVariables,
|
self._connection.DoRequest( partial( self._ConsumeVariables,
|
||||||
view.draw,
|
view.draw,
|
||||||
variable ), {
|
variable ), {
|
||||||
|
|
@ -352,7 +357,7 @@ class VariablesView( object ):
|
||||||
indent = ' ' * ( indent - 1 ),
|
indent = ' ' * ( indent - 1 ),
|
||||||
marker = '*' if variable.changed else ' ',
|
marker = '*' if variable.changed else ' ',
|
||||||
icon = '+' if ( variable.IsExpandable()
|
icon = '+' if ( variable.IsExpandable()
|
||||||
and not variable.IsExpandedByUser() ) else '-',
|
and not variable.IsExpanded() ) else '-',
|
||||||
name = variable.variable[ 'name' ],
|
name = variable.variable[ 'name' ],
|
||||||
type_ = variable.variable.get( 'type', '<unknown type>' ),
|
type_ = variable.variable.get( 'type', '<unknown type>' ),
|
||||||
value = variable.variable.get( 'value',
|
value = variable.variable.get( 'value',
|
||||||
|
|
@ -390,7 +395,7 @@ class VariablesView( object ):
|
||||||
self._DrawWatchResult( 2, watch )
|
self._DrawWatchResult( 2, watch )
|
||||||
|
|
||||||
def _DrawScope( self, indent, scope ):
|
def _DrawScope( self, indent, scope ):
|
||||||
icon = '+' if scope.IsExpandable() and not scope.IsExpandedByUser() else '-'
|
icon = '+' if scope.IsExpandable() and not scope.IsExpanded() else '-'
|
||||||
|
|
||||||
line = utils.AppendToBuffer( self._vars.buf,
|
line = utils.AppendToBuffer( self._vars.buf,
|
||||||
'{0}{1} Scope: {2}'.format(
|
'{0}{1} Scope: {2}'.format(
|
||||||
|
|
@ -409,7 +414,7 @@ class VariablesView( object ):
|
||||||
|
|
||||||
assert indent > 0
|
assert indent > 0
|
||||||
icon = '+' if ( watch.result.IsExpandable() and
|
icon = '+' if ( watch.result.IsExpandable() and
|
||||||
not watch.result.IsExpandedByUser() ) else '-'
|
not watch.result.IsExpanded() ) else '-'
|
||||||
|
|
||||||
line = '{indent}{marker}{icon} Result: {result}'.format(
|
line = '{indent}{marker}{icon} Result: {result}'.format(
|
||||||
# We borrow 1 space of indent to draw the change marker
|
# We borrow 1 space of indent to draw the change marker
|
||||||
|
|
@ -446,7 +451,7 @@ class VariablesView( object ):
|
||||||
|
|
||||||
new_variables.append( variable )
|
new_variables.append( variable )
|
||||||
|
|
||||||
if variable.IsExpandable() and variable.IsExpandedByUser():
|
if variable.IsExpandable() and variable.IsExpanded():
|
||||||
self._connection.DoRequest( partial( self._ConsumeVariables,
|
self._connection.DoRequest( partial( self._ConsumeVariables,
|
||||||
draw,
|
draw,
|
||||||
variable ), {
|
variable ), {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue