Refactor config file to set adapter properties independently

This can later be extended to set adapter properties globally.
This commit is contained in:
Ben Jackson 2018-05-28 16:11:11 +01:00
commit bac30acff3
2 changed files with 87 additions and 71 deletions

View file

@ -1,12 +1,31 @@
{ {
"simple_c_program - lldb-mi Launch": { "adapters": {
"adapter": { "lldb-mi": {
"name": "lldb-mi", "name": "lldb-mi",
"command": [ "command": [
"node", "node",
"/Users/ben/.vscode/extensions/webfreak.debug-0.22.0/out/src/lldb.js" "/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"
]
}
},
"configurations": {
"simple_c_program - lldb-mi Launch": {
"adapter": "lldb-mi",
"configuration": { "configuration": {
"request": "launch", "request": "launch",
"target": "support/test/cpp/simple_c_program/test", "target": "support/test/cpp/simple_c_program/test",
@ -18,10 +37,7 @@
} }
}, },
"simple_c_progra - ms Launch": { "simple_c_progra - ms Launch": {
"adapter": { "adapter": "cppdbg",
"name": "cppdbg",
"command": [ "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/OpenDebugAD7" ]
},
"configuration": { "configuration": {
"name": "ms Launch", "name": "ms Launch",
"type": "cppdbg", "type": "cppdbg",
@ -35,13 +51,7 @@
} }
}, },
"simple_python - launch": { "simple_python - launch": {
"adapter": { "adapter": "python",
"name": "python",
"command": [
"node",
"/Users/ben/.vscode/extensions/ms-python.python-2018.4.0/out/client/debugger/Main.js"
]
},
"configuration": { "configuration": {
"name": "Python: Current File", "name": "Python: Current File",
"type": "python", "type": "python",
@ -54,14 +64,7 @@
} }
}, },
"simple_c_program - MS Attach": { "simple_c_program - MS Attach": {
"adapter": { "adapter": "cppdbg",
"name": "cppdbg",
"command": [ "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/OpenDebugAD7" ],
"attach": {
"pidProperty": "processId",
"pidSelect": "ask"
}
},
"configuration": { "configuration": {
"name": "(lldb) Attach", "name": "(lldb) Attach",
"type": "cppdbg", "type": "cppdbg",
@ -70,4 +73,5 @@
"MIMode": "lldb" "MIMode": "lldb"
} }
} }
}
} }

View file

@ -84,6 +84,9 @@ class DebugSession( object ):
def Start( self, configuration = None ): def Start( self, configuration = None ):
self._configuration = None
self._adapter = None
launch_config_file = utils.PathToConfigFile( '.vimspector.json' ) launch_config_file = utils.PathToConfigFile( '.vimspector.json' )
if not launch_config_file: if not launch_config_file:
@ -92,7 +95,10 @@ class DebugSession( object ):
return return
with open( launch_config_file, 'r' ) as f: 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 not configuration:
if len( launch_config ) == 1: if len( launch_config ) == 1:
@ -104,6 +110,12 @@ class DebugSession( object ):
if not configuration: if not configuration:
return 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 ] self._configuration = launch_config[ configuration ]
def start(): def start():
@ -269,11 +281,11 @@ class DebugSession( object ):
def _StartDebugAdapter( self ): def _StartDebugAdapter( self ):
self._logger.info( 'Starting debug adapter with: {0}'.format( json.dumps( self._logger.info( 'Starting debug adapter with: {0}'.format( json.dumps(
self._configuration[ 'adapter' ] ) ) ) self._adapter ) ) )
channel_send_func = vim.bindeval( channel_send_func = vim.bindeval(
"vimspector#internal#job#StartDebugSession( {0} )".format( "vimspector#internal#job#StartDebugSession( {0} )".format(
json.dumps( self._configuration[ 'adapter' ] ) ) ) json.dumps( self._adapter ) ) )
self._connection = debug_adapter_connection.DebugAdapterConnection( self._connection = debug_adapter_connection.DebugAdapterConnection(
self, self,
@ -338,10 +350,10 @@ class DebugSession( object ):
def _Initialise( self ): def _Initialise( self ):
adapter_config = self._configuration[ 'adapter' ] adapter_config = self._adapter
launch_config = self._configuration[ 'configuration' ] launch_config = self._configuration[ 'configuration' ]
if 'attach' in adapter_config: if launch_config.get( 'request' ) == "attach":
self._SelectProcess( adapter_config, launch_config ) self._SelectProcess( adapter_config, launch_config )
self._connection.DoRequest( None, { self._connection.DoRequest( None, {