@@ -135,6 +135,10 @@ def as_dict(self):
135135 return source_dict
136136
137137
138+ class NotSupportedError (Exception ):
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" :
@@ -488,13 +495,11 @@ def wait_for_terminated(self, timeout: Optional[float] = None):
488495 raise ValueError ("didn't get terminated event" )
489496 return event_dict
490497
491- def get_initialize_value (self , key ):
498+ def get_capability (self , key , default = None ):
492499 """Get a value for the given key if it there is a key/value pair in
493- the "initialize" request response body .
500+ the capabilities reported by the adapter .
494501 """
495- if self .initialize_body and key in self .initialize_body :
496- return self .initialize_body [key ]
497- return None
502+ return self .capabilities .get (key , default )
498503
499504 def get_threads (self ):
500505 if self .threads is None :
@@ -760,6 +765,10 @@ def request_continue(self, threadId=None, singleThread=False):
760765 return response
761766
762767 def request_restart (self , restartArguments = None ):
768+ if self .exit_status is not None :
769+ raise ValueError ("request_restart called after process exited" )
770+ if not self .get_capability ("supportsRestartRequest" , False ):
771+ raise NotSupportedError ("supportsRestartRequest is not set" )
763772 command_dict = {
764773 "command" : "restart" ,
765774 "type" : "request" ,
@@ -867,7 +876,7 @@ def request_initialize(self, sourceInitFile=False):
867876 response = self .send_recv (command_dict )
868877 if response :
869878 if "body" in response :
870- self .initialize_body = response ["body" ]
879+ self .capabilities = response ["body" ]
871880 return response
872881
873882 def request_launch (
@@ -972,6 +981,8 @@ def request_stepIn(self, threadId, targetId, granularity="statement"):
972981 def request_stepInTargets (self , frameId ):
973982 if self .exit_status is not None :
974983 raise ValueError ("request_stepInTargets called after process exited" )
984+ if not self .get_capability ("supportsStepInTargetsRequest" , False ):
985+ raise NotSupportedError ("supportsStepInTargetsRequest is not set" )
975986 args_dict = {"frameId" : frameId }
976987 command_dict = {
977988 "command" : "stepInTargets" ,
0 commit comments