diff --git a/.vimspector.json b/.vimspector.json index ef8a3e0..06dfdc5 100644 --- a/.vimspector.json +++ b/.vimspector.json @@ -1,73 +1,77 @@ { - "simple_c_program - lldb-mi Launch": { - "adapter": { - "name": "lldb-mi", - "command": [ - "node", - "/Users/ben/.vscode/extensions/webfreak.debug-0.22.0/out/src/lldb.js" - ] - }, - "configuration": { - "request": "launch", - "target": "support/test/cpp/simple_c_program/test", - "args": [], - "cwd": ".", - "lldbmipath": "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/lldb/bin/lldb-mi", - "trace": true, - "logFilePath": "/Users/ben/.vimspector.protocol.log" - } + "adapters": { + "lldb-mi": { + "name": "lldb-mi", + "command": [ + "node", + "/Users/ben/.vscode/extensions/webfreak.debug-0.22.0/out/src/lldb.js" + ] + }, + "cppdbg": { + "name": "cppdbg", + "command": [ "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/OpenDebugAD7" ], + "attach": { + "pidProperty": "processId", + "pidSelect": "ask" + } + }, + "python": { + "name": "python", + "command": [ + "node", + "/Users/ben/.vscode/extensions/ms-python.python-2018.4.0/out/client/debugger/Main.js" + ] + } }, - "simple_c_progra - ms Launch": { - "adapter": { - "name": "cppdbg", - "command": [ "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/OpenDebugAD7" ] - }, - "configuration": { - "name": "ms Launch", - "type": "cppdbg", - "request": "launch", - "program": "/Users/ben/.vim/bundle/vimspector/support/test/cpp/simple_c_program/test", - "args": [], - "cwd": "/Users/ben", - "environment": [], - "externalConsole": true, - "MIMode": "lldb" - } - }, - "simple_python - launch": { - "adapter": { - "name": "python", - "command": [ - "node", - "/Users/ben/.vscode/extensions/ms-python.python-2018.4.0/out/client/debugger/Main.js" - ] - }, - "configuration": { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "cwd": "/Users/ben/.vim/bundle/vimspector/support/test/python/simple_python", - "stopOnEntry": true, - "console": "externalTerminal", - "debugOptions": [], - "program": "/Users/ben/.vim/bundle/vimspector/support/test/python/simple_python/main.py" - } - }, - "simple_c_program - MS Attach": { - "adapter": { - "name": "cppdbg", - "command": [ "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/OpenDebugAD7" ], - "attach": { - "pidProperty": "processId", - "pidSelect": "ask" + "configurations": { + "simple_c_program - lldb-mi Launch": { + "adapter": "lldb-mi", + "configuration": { + "request": "launch", + "target": "support/test/cpp/simple_c_program/test", + "args": [], + "cwd": ".", + "lldbmipath": "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/lldb/bin/lldb-mi", + "trace": true, + "logFilePath": "/Users/ben/.vimspector.protocol.log" } }, - "configuration": { - "name": "(lldb) Attach", - "type": "cppdbg", - "request": "attach", - "program": "/Users/ben/.vim/bundle/vimspector/support/test/cpp/simple_c_program/test", - "MIMode": "lldb" + "simple_c_progra - ms Launch": { + "adapter": "cppdbg", + "configuration": { + "name": "ms Launch", + "type": "cppdbg", + "request": "launch", + "program": "/Users/ben/.vim/bundle/vimspector/support/test/cpp/simple_c_program/test", + "args": [], + "cwd": "/Users/ben", + "environment": [], + "externalConsole": true, + "MIMode": "lldb" + } + }, + "simple_python - launch": { + "adapter": "python", + "configuration": { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "cwd": "/Users/ben/.vim/bundle/vimspector/support/test/python/simple_python", + "stopOnEntry": true, + "console": "externalTerminal", + "debugOptions": [], + "program": "/Users/ben/.vim/bundle/vimspector/support/test/python/simple_python/main.py" + } + }, + "simple_c_program - MS Attach": { + "adapter": "cppdbg", + "configuration": { + "name": "(lldb) Attach", + "type": "cppdbg", + "request": "attach", + "program": "/Users/ben/.vim/bundle/vimspector/support/test/cpp/simple_c_program/test", + "MIMode": "lldb" + } } } } diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index c11799a..d93e966 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -84,6 +84,9 @@ class DebugSession( object ): def Start( self, configuration = None ): + self._configuration = None + self._adapter = None + launch_config_file = utils.PathToConfigFile( '.vimspector.json' ) if not launch_config_file: @@ -92,7 +95,10 @@ class DebugSession( object ): return with open( launch_config_file, 'r' ) as f: - launch_config = json.load( f ) + database = json.load( f ) + + launch_config = database.get( 'configurations' ) + adapters = database.get( 'adapters' ) if not configuration: if len( launch_config ) == 1: @@ -104,6 +110,12 @@ class DebugSession( object ): if not configuration: return + adapter = launch_config[ configuration ].get( 'adapter' ) + if isinstance( adapter, str ): + self._adapter = adapters.get( adapter ) + else: + self._adapter = adapter + self._configuration = launch_config[ configuration ] def start(): @@ -269,11 +281,11 @@ class DebugSession( object ): def _StartDebugAdapter( self ): self._logger.info( 'Starting debug adapter with: {0}'.format( json.dumps( - self._configuration[ 'adapter' ] ) ) ) + self._adapter ) ) ) channel_send_func = vim.bindeval( "vimspector#internal#job#StartDebugSession( {0} )".format( - json.dumps( self._configuration[ 'adapter' ] ) ) ) + json.dumps( self._adapter ) ) ) self._connection = debug_adapter_connection.DebugAdapterConnection( self, @@ -338,10 +350,10 @@ class DebugSession( object ): def _Initialise( self ): - adapter_config = self._configuration[ 'adapter' ] + adapter_config = self._adapter launch_config = self._configuration[ 'configuration' ] - if 'attach' in adapter_config: + if launch_config.get( 'request' ) == "attach": self._SelectProcess( adapter_config, launch_config ) self._connection.DoRequest( None, {