1919from functools import partial
2020import typing
2121
22- from vimspector import utils , settings
22+ from vimspector import utils , settings , session_manager
2323from vimspector .debug_adapter_connection import DebugAdapterConnection
2424
2525
@@ -67,7 +67,7 @@ def FrameID( self ):
6767 assert False
6868
6969 @abc .abstractmethod
70- def EvaluateName ( self ):
70+ def Name ( self ):
7171 assert False
7272
7373 @abc .abstractmethod
@@ -78,6 +78,9 @@ def MemoryReference( self ):
7878 def HoverText ( self ):
7979 return ""
8080
81+ def Update ( self , connection ):
82+ self .connection = connection
83+
8184
8285class Scope ( Expandable ):
8386 """Holds an expandable scope (a DAP scope dict), with expand/collapse state"""
@@ -94,10 +97,11 @@ def MemoryReference( self ):
9497 def FrameID ( self ):
9598 return None
9699
97- def EvaluateName ( self ):
100+ def Name ( self ):
98101 return self .scope [ 'name' ]
99102
100- def Update ( self , scope ):
103+ def Update ( self , connection , scope ):
104+ super ().Update ( connection )
101105 self .scope = scope
102106
103107 def HoverText ( self ):
@@ -125,10 +129,11 @@ def MemoryReference( self ):
125129 def FrameID ( self ):
126130 return self .watch .expression .get ( 'frameId' )
127131
128- def EvaluateName ( self ):
132+ def Name ( self ):
129133 return self .watch .expression .get ( 'expression' )
130134
131- def Update ( self , result ):
135+ def Update ( self , connection , result ):
136+ super ().Update ( connection )
132137 self .changed = False
133138 if self .result [ 'result' ] != result [ 'result' ]:
134139 self .changed = True
@@ -145,8 +150,8 @@ def HoverText( self ):
145150
146151
147152class WatchFailure ( WatchResult ):
148- def __init__ ( self , connection : DebugAdapterConnection , reason ):
149- super ().__init__ ( connection , { 'result' : reason } )
153+ def __init__ ( self , connection : DebugAdapterConnection , watch , reason ):
154+ super ().__init__ ( connection , watch , { 'result' : reason } )
150155 self .changed = True
151156
152157
@@ -170,10 +175,11 @@ def MemoryReference( self ):
170175 def FrameID ( self ):
171176 return self .container .FrameID ()
172177
173- def EvaluateName ( self ):
174- return self .variable . get ( 'evaluateName' , self . variable [ 'name' ] )
178+ def Name ( self ):
179+ return self .variable [ 'name' ]
175180
176- def Update ( self , variable ):
181+ def Update ( self , connection , variable ):
182+ super ().Update ( connection )
177183 self .changed = False
178184 if self .variable [ 'value' ] != variable [ 'value' ]:
179185 self .changed = True
@@ -201,6 +207,11 @@ def __init__( self, connection: DebugAdapterConnection, expression: dict ):
201207 self .result = None
202208
203209 def SetCurrentFrame ( self , connection , frame ):
210+ if connection is None :
211+ self .connection = None
212+ self .result .connection = None
213+ return
214+
204215 if self .connection is None :
205216 self .connection = connection
206217 elif self .connection != connection :
@@ -253,6 +264,9 @@ def AddExpandMappings( mappings = None ):
253264 for mapping in utils .GetVimList ( mappings , 'read_memory' ):
254265 vim .command ( f'nnoremap <silent> <buffer> { mapping } '
255266 ':<C-u>call vimspector#ReadMemory()<CR>' )
267+ for mapping in utils .GetVimList ( mappings , 'add_data_breakpoint' ):
268+ vim .command ( f'nnoremap <silent> <buffer> { mapping } '
269+ ':<C-u>call vimspector#AddDataBreakpoint()<CR>' )
256270
257271
258272
@@ -348,7 +362,7 @@ def ConnectionClosed( self, connection ):
348362 ]
349363 for w in self ._watches :
350364 if w .connection == connection :
351- w .connection = None
365+ w .SetCurrentFrame ( None , None )
352366
353367
354368 def Reset ( self ):
@@ -388,7 +402,7 @@ def scopes_consumer( message ):
388402 if not found :
389403 scope = Scope ( connection , scope_body )
390404 else :
391- scope .Update ( scope_body )
405+ scope .Update ( connection , scope_body )
392406
393407 new_scopes .append ( scope )
394408
@@ -459,9 +473,9 @@ def handler( message ):
459473
460474 watch = self ._variable_eval
461475 if watch .result is None or watch .result .connection != connection :
462- watch .result = WatchResult ( connection , message [ 'body' ] )
476+ watch .result = WatchResult ( connection , watch , message [ 'body' ] )
463477 else :
464- watch .result .Update ( message [ 'body' ] )
478+ watch .result .Update ( connection , message [ 'body' ] )
465479
466480 popup_win_id = utils .CreateTooltip ( [], is_hover )
467481 # record the global eval window id
@@ -566,10 +580,10 @@ def EvaluateWatches( self,
566580
567581 def _UpdateWatchExpression ( self , watch : Watch , message : dict ):
568582 if watch .result is not None :
569- watch .result .Update ( message [ 'body' ] )
583+ watch .result .Update ( watch . connection , message [ 'body' ] )
570584 else :
571585 watch .result = WatchResult ( watch .connection ,
572- watch [ 'frameId' ] ,
586+ watch ,
573587 message [ 'body' ] )
574588
575589 if ( watch .result .IsExpandable () and
@@ -590,7 +604,7 @@ def _WatchExpressionFailed( self, reason: str, watch: Watch ):
590604 # We already have a result for this watch. Wut ?
591605 return
592606
593- watch .result = WatchFailure ( watch .connection , reason )
607+ watch .result = WatchFailure ( watch .connection , watch , reason )
594608 self ._DrawWatches ()
595609
596610 def _GetVariable ( self , buf = None , line_num = None ):
@@ -682,7 +696,7 @@ def handler( message ):
682696 },
683697 } )
684698
685- variable .Update ( new_variable )
699+ variable .Update ( variable . connection , new_variable )
686700 view .draw ()
687701
688702 def failure_handler ( reason , message ):
@@ -714,15 +728,17 @@ def GetDataBreakpointInfo( self,
714728 variable : Expandable
715729 view : View
716730
717- if not self ._server_capabilities .get ( 'supportsDataBreakpoints' ):
718- return None
719-
720731 variable , view = self ._GetVariable ( buf , line_num )
721732 if variable is None :
722733 return None
723734
735+ if not session_manager .Get ().GetSession (
736+ variable .connection .GetSessionId () )._server_capabilities .get (
737+ 'supportsDataBreakpoints' ):
738+ return None
739+
724740 arguments = {
725- 'name' : variable .EvaluateName ()
741+ 'name' : variable .Name ()
726742 }
727743 frameId = variable .FrameID ()
728744 if frameId :
@@ -732,7 +748,8 @@ def GetDataBreakpointInfo( self,
732748 arguments [ 'variablesReference' ] = (
733749 variable .container .VariablesReference () )
734750
735- variable .connection .DoRequest ( lambda msg : then ( msg [ 'body' ] ), {
751+ variable .connection .DoRequest ( lambda msg : then ( variable .connection ,
752+ msg [ 'body' ] ), {
736753 'command' : 'dataBreakpointInfo' ,
737754 'arguments' : arguments ,
738755 } )
@@ -886,7 +903,7 @@ def _ConsumeVariables( self, draw, parent, message ):
886903 if not found :
887904 variable = Variable ( parent .connection , parent , variable_body )
888905 else :
889- variable .Update ( variable_body )
906+ variable .Update ( parent . connection , variable_body )
890907
891908 new_variables .append ( variable )
892909
0 commit comments