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,73 +1,77 @@
{ {
"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"
] ]
}, },
"configuration": { "cppdbg": {
"request": "launch", "name": "cppdbg",
"target": "support/test/cpp/simple_c_program/test", "command": [ "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/OpenDebugAD7" ],
"args": [], "attach": {
"cwd": ".", "pidProperty": "processId",
"lldbmipath": "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/lldb/bin/lldb-mi", "pidSelect": "ask"
"trace": true, }
"logFilePath": "/Users/ben/.vimspector.protocol.log" },
} "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": { "configurations": {
"adapter": { "simple_c_program - lldb-mi Launch": {
"name": "cppdbg", "adapter": "lldb-mi",
"command": [ "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/OpenDebugAD7" ] "configuration": {
}, "request": "launch",
"configuration": { "target": "support/test/cpp/simple_c_program/test",
"name": "ms Launch", "args": [],
"type": "cppdbg", "cwd": ".",
"request": "launch", "lldbmipath": "/Users/ben/.vscode/extensions/ms-vscode.cpptools-0.17.3/debugAdapters/lldb/bin/lldb-mi",
"program": "/Users/ben/.vim/bundle/vimspector/support/test/cpp/simple_c_program/test", "trace": true,
"args": [], "logFilePath": "/Users/ben/.vimspector.protocol.log"
"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"
} }
}, },
"configuration": { "simple_c_progra - ms Launch": {
"name": "(lldb) Attach", "adapter": "cppdbg",
"type": "cppdbg", "configuration": {
"request": "attach", "name": "ms Launch",
"program": "/Users/ben/.vim/bundle/vimspector/support/test/cpp/simple_c_program/test", "type": "cppdbg",
"MIMode": "lldb" "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"
}
} }
} }
} }

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, {