From e216bc291d4e3363b663d5859878dde4c9c3efdc Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 21 Feb 2019 16:14:05 +0000 Subject: [PATCH] Respect (some) server capabilities --- python3/vimspector/debug_session.py | 63 ++++++++++++++++++----------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index b27a060..a2a3680 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -66,6 +66,7 @@ class DebugSession( object ): self._configuration = None self._init_complete = False self._launch_complete = False + self._server_capabilities = {} def ToggleBreakpoint( self ): line, column = vim.current.window.cursor @@ -437,11 +438,11 @@ class DebugSession( object ): self._connection.DoRequest( handler, { 'command': 'disconnect', - 'arguments': { - 'terminateDebugee': True - }, + 'arguments': arguments, }, failure_handler = handler, timeout = 5000 ) + # TODO: Use the 'tarminate' request if supportsTerminateRequest set + def _PrepareAttach( self, adapter_config, launch_config ): atttach_config = adapter_config.get( 'attach' ) @@ -548,11 +549,14 @@ class DebugSession( object ): return commands def _Initialise( self ): - adapter_config = self._adapter - self._connection.DoRequest( lambda msg: self._Launch(), { + def handle_initialize_response( msg ): + self._server_capabilities = msg.get( 'body' ) or {} + self._Launch() + + self._connection.DoRequest( handle_initialize_response, { 'command': 'initialize', 'arguments': { - 'adapterID': adapter_config.get( 'name', 'adapter' ), + 'adapterID': self._adapter.get( 'name', 'adapter' ), 'clientID': 'vimspector', 'clientName': 'vimspector', 'linesStartAt1': True, @@ -632,18 +636,30 @@ class DebugSession( object ): if self._launch_complete and self._init_complete: self._stackTraceView.LoadThreads( True ) + + def OnEvent_capabiilities( self, msg ): + self._server_capabilities.update( + ( msg.get( 'body' ) or {} ).get( 'capabilities' ) or {} ) + + def OnEvent_initialized( self, message ): self._SendBreakpoints() - self._connection.DoRequest( - lambda msg: self._OnInitializeComplete(), - { - 'command': 'configurationDone', - } - ) + + if self._server_capabilities.get( 'supportsConfigurationDoneRequest' ): + self._connection.DoRequest( + lambda msg: self._OnInitializeComplete(), + { + 'command': 'configurationDone', + } + ) + else: + self._OnInitializeComplete() + def OnEvent_thread( self, message ): self._stackTraceView.OnThreadEvent( message[ 'body' ] ) + def OnEvent_breakpoint( self, message ): reason = message[ 'body' ][ 'reason' ] bp = message[ 'body' ][ 'breakpoint' ] @@ -748,18 +764,19 @@ class DebugSession( object ): } ) - self._connection.DoRequest( - functools.partial( self._UpdateBreakpoints, None ), - { - 'command': 'setFunctionBreakpoints', - 'arguments': { - 'breakpoints': [ - { 'name': bp[ 'function' ] } - for bp in self._func_breakpoints if bp[ 'state' ] == 'ENABLED' - ], + if self._server_capabilities.get( 'supportsFunctionBreakpoints' ): + self._connection.DoRequest( + functools.partial( self._UpdateBreakpoints, None ), + { + 'command': 'setFunctionBreakpoints', + 'arguments': { + 'breakpoints': [ + { 'name': bp[ 'function' ] } + for bp in self._func_breakpoints if bp[ 'state' ] == 'ENABLED' + ], + } } - } - ) + ) def _ShowBreakpoints( self ): for file_name, line_breakpoints in self._line_breakpoints.items():