@@ -135,6 +135,10 @@ def as_dict(self):
135135 return source_dict
136136
137137
138+ class NotSupportedError (KeyError ):
139+ """Raised if a feature is not supported due to its capabilities."""
140+
141+
138142class DebugCommunication (object ):
139143 def __init__ (
140144 self ,
@@ -153,7 +157,7 @@ def __init__(
153157 self .recv_thread = threading .Thread (target = self ._read_packet_thread )
154158 self .process_event_body = None
155159 self .exit_status : Optional [int ] = None
156- self .initialize_body = None
160+ self .capabilities : dict [ str , Any ] = {}
157161 self .progress_events : list [Event ] = []
158162 self .reverse_requests = []
159163 self .sequence = 1
@@ -300,6 +304,9 @@ def _handle_recv_packet(self, packet: Optional[ProtocolMessage]) -> bool:
300304 elif event == "breakpoint" :
301305 # Breakpoint events are sent when a breakpoint is resolved
302306 self ._update_verified_breakpoints ([body ["breakpoint" ]])
307+ elif event == "capabilities" :
308+ # Update the capabilities with new ones from the event.
309+ self .capabilities .update (body ["capabilities" ])
303310
304311 elif packet_type == "response" :
305312 if packet ["command" ] == "disconnect" :
@@ -487,13 +494,13 @@ def wait_for_terminated(self, timeout: Optional[float] = None):
487494 raise ValueError ("didn't get terminated event" )
488495 return event_dict
489496
490- def get_initialize_value (self , key ):
497+ def get_capability (self , key ):
491498 """Get a value for the given key if it there is a key/value pair in
492- the "initialize" request response body .
499+ the capabilities reported by the adapter .
493500 """
494- if self . initialize_body and key in self .initialize_body :
495- return self .initialize_body [key ]
496- return None
501+ if key in self .capabilities :
502+ return self .capabilities [key ]
503+ raise NotSupportedError ( key )
497504
498505 def get_threads (self ):
499506 if self .threads is None :
@@ -759,6 +766,9 @@ def request_continue(self, threadId=None, singleThread=False):
759766 return response
760767
761768 def request_restart (self , restartArguments = None ):
769+ if self .exit_status is not None :
770+ raise ValueError ("request_restart called after process exited" )
771+ self .get_capability ("supportsRestartRequest" )
762772 command_dict = {
763773 "command" : "restart" ,
764774 "type" : "request" ,
@@ -866,7 +876,7 @@ def request_initialize(self, sourceInitFile=False):
866876 response = self .send_recv (command_dict )
867877 if response :
868878 if "body" in response :
869- self .initialize_body = response ["body" ]
879+ self .capabilities = response ["body" ]
870880 return response
871881
872882 def request_launch (
@@ -971,6 +981,7 @@ def request_stepIn(self, threadId, targetId, granularity="statement"):
971981 def request_stepInTargets (self , frameId ):
972982 if self .exit_status is not None :
973983 raise ValueError ("request_stepInTargets called after process exited" )
984+ self .get_capability ("supportsStepInTargetsRequest" )
974985 args_dict = {"frameId" : frameId }
975986 command_dict = {
976987 "command" : "stepInTargets" ,
0 commit comments