diff --git a/src/debug.ts b/src/debug.ts index e0e72ca..823a802 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -306,7 +306,8 @@ async function mergeLaunchConfig( (config) => config.configId === configId ); const name = createName(board, programmer); - const launchConfig = { + // Create base configuration data + let launchConfig = { configId, cwd: '${workspaceRoot}', request: 'launch', @@ -315,17 +316,26 @@ async function mergeLaunchConfig( ...(debugInfo.customConfigs ? debugInfo.customConfigs[cortexDebug] ?? {} : {}), - ...(customConfig ? customConfig : {}), name, }; + + // Remap Arduino CLI debug config properties to launch.json keys replaceValue('serverPath', 'serverpath', launchConfig); replaceValue('server', 'servertype', launchConfig); replaceValue('toolchainPath', 'armToolchainPath', launchConfig); replaceValue('serverConfiguration.scripts', 'configFiles', launchConfig); + // Remove unused Arduino CLI debug config data unsetValue(launchConfig, 'customConfigs'); unsetValue(launchConfig, 'serverConfiguration'); unsetValue(launchConfig, 'programmer'); // The programmer is not used by the debugger https://github.com/arduino/arduino-cli/pull/2391 unsetValue(launchConfig, 'toolchain'); // The toolchain is also unused by IDE2 or the cortex-debug VSIX + + // Merge configuration from debug_custom.json + launchConfig = { + ...launchConfig, + ...(customConfig ? customConfig : {}), + }; + return launchConfig; } diff --git a/src/test/suite/debug.test.ts b/src/test/suite/debug.test.ts index b2c5cb9..075e1e6 100644 --- a/src/test/suite/debug.test.ts +++ b/src/test/suite/debug.test.ts @@ -144,8 +144,27 @@ describe('debug', () => { const actual = await mergeLaunchConfig( board, programmer, - { executable }, - [{ configId, cwd: 'alma' }] + { + executable, + toolchainPrefix: 'toolchain-prefix', + serverPath: 'path/to/server', + server: 'openocd', + toolchainPath: 'path/to/toolchain', + serverConfiguration: { + scripts: ['path/to/config-file'], + }, + }, + [ + { + configId, + cwd: 'alma', + toolchainPrefix: 'custom-toolchain-prefix', + serverpath: '/path/to/custom-server', + servertype: 'jlink', + armToolchainPath: '/path/to/custom-arm-toolchain', + configFiles: ['/path/to/custom-config'], + }, + ] ); assert.deepStrictEqual(actual, { configId, @@ -154,6 +173,11 @@ describe('debug', () => { name: 'ABC (p1)', request: 'launch', type: 'cortex-debug', + toolchainPrefix: 'custom-toolchain-prefix', + serverpath: '/path/to/custom-server', + servertype: 'jlink', + armToolchainPath: '/path/to/custom-arm-toolchain', + configFiles: ['/path/to/custom-config'], }); }); @@ -230,8 +254,11 @@ describe('debug', () => { const actual = await mergeLaunchConfig( board, programmer, - { executable }, - [{ configId, [key]: value }] + { + executable, + [key]: value, + }, + [] ); assert.deepStrictEqual(actual, expected); })