From 23ef81020ee43c0f56ae3bd16877ac5afcc0389e Mon Sep 17 00:00:00 2001 From: Mate Pek Date: Mon, 22 Nov 2021 20:23:09 +0100 Subject: [PATCH] master: support advanced sourceMap from launch.json --- CHANGELOG.md | 2 ++ src/Configurations.ts | 33 +++++++++++++++++++++++---------- src/WorkspaceManager.ts | 15 ++++++++------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 848d554e..3df80a72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## [4.0.2] + ### Added - basic support of `terminal.integrated.env.*`. Limitation: changes of the config are not detected. diff --git a/src/Configurations.ts b/src/Configurations.ts index a2390ab2..e61334fe 100644 --- a/src/Configurations.ts +++ b/src/Configurations.ts @@ -93,8 +93,8 @@ export class Configurations { return vscode.extensions.all.find(e => e.id === id) !== undefined; } - public getDebugConfigurationTemplate(): [vscode.DebugConfiguration, string] { - const [template, source] = ((): [vscode.DebugConfiguration, string] => { + public getDebugConfigurationTemplate(): DebugConfigData { + const debugConfigData = ((): DebugConfigData => { const templateFromConfig = this._getD( 'debug.configTemplate', null, @@ -110,7 +110,7 @@ export class Configurations { Object.assign(template, templateFromConfig); this._log.debug('template', template); - return [template, 'userDefined']; + return { template, source: 'userDefined', launchSourceFileMap: {} }; } else if (templateFromConfig === null) { const wpLaunchConfigs = vscode.workspace .getConfiguration('launch', this._workspaceFolderUri) @@ -162,7 +162,7 @@ export class Configurations { template, ); - return [template, 'fromLaunchJson']; + return { template, source: 'fromLaunchJson', launchSourceFileMap: wpLaunchConfigs[i].sourceFileMap }; } } } @@ -178,7 +178,7 @@ export class Configurations { sourceMap: '${sourceFileMapObj}', }); - return [template, 'vadimcn.vscode-lldb']; + return { template, source: 'vadimcn.vscode-lldb', launchSourceFileMap: {} }; } else if (this._hasExtension('webfreak.debug')) { Object.assign(template, { type: 'gdb', @@ -197,7 +197,7 @@ export class Configurations { template.lldbmipath = '/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi'; } - return [template, 'webfreak.debug']; + return { template, source: 'webfreak.debug', launchSourceFileMap: {} }; } else if (this._hasExtension('ms-vscode.cpptools')) { // documentation says debug"environment" = [{...}] but that doesn't work Object.assign(template, { @@ -213,7 +213,7 @@ export class Configurations { sourceFileMap: '${sourceFileMapObj}', }); - return [template, 'ms-vscode.cpptools']; + return { template, source: 'ms-vscode.cpptools', launchSourceFileMap: {} }; } this._log.info('no debug config'); @@ -222,10 +222,10 @@ export class Configurations { ); })(); - const platfromProp = platformUtil.getPlatformProperty(template); - if (typeof platfromProp === 'object') Object.assign(template, platfromProp); + const platfromProp = platformUtil.getPlatformProperty(debugConfigData.template); + if (typeof platfromProp === 'object') Object.assign(debugConfigData.template, platfromProp); - return [template, source]; + return debugConfigData; } public getOrCreateUserId(): string { @@ -604,3 +604,16 @@ export class Configurations { return {}; } } + +export type DebugConfigTemplateSource = + | 'fromLaunchJson' + | 'userDefined' + | 'vadimcn.vscode-lldb' + | 'ms-vscode.cpptools' + | 'webfreak.debug'; + +export type DebugConfigData = { + template: vscode.DebugConfiguration; + source: DebugConfigTemplateSource; + launchSourceFileMap?: Record; +}; diff --git a/src/WorkspaceManager.ts b/src/WorkspaceManager.ts index 94a5bfd9..fd8911a6 100644 --- a/src/WorkspaceManager.ts +++ b/src/WorkspaceManager.ts @@ -396,9 +396,9 @@ export class WorkspaceManager implements vscode.Disposable { const argsArrayFunc = async (): Promise => argsArray; - const [debugConfigTemplate, debugConfigTemplateSource] = configuration.getDebugConfigurationTemplate(); + const debugConfigData = configuration.getDebugConfigurationTemplate(); - this._shared.log.debug('debugConfigTemplate', { debugConfigTemplateSource, debugConfigTemplate }); + this._shared.log.debug('debugConfigTemplate', { debugConfigTemplate: debugConfigData }); // if (!TestAdapter._debugMetricSent) { // this._shared.log.infoSWithTags('Using debug', { debugConfigTemplateSource }); @@ -409,9 +409,9 @@ export class WorkspaceManager implements vscode.Disposable { { const setEnvKey = 'testMate.cpp.debug.setEnv'; - if (typeof debugConfigTemplate[setEnvKey] === 'object') { - for (const envName in debugConfigTemplate[setEnvKey]) { - const envValue = debugConfigTemplate[setEnvKey][envName]; + if (typeof debugConfigData.template[setEnvKey] === 'object') { + for (const envName in debugConfigData.template[setEnvKey]) { + const envValue = debugConfigData.template[setEnvKey][envName]; if (typeof envValue !== 'string') this._shared.log.warn( 'Wrong value. testMate.cpp.debug.setEnv should contains only string values', @@ -449,11 +449,12 @@ export class WorkspaceManager implements vscode.Disposable { }, { resolve: '${sourceFileMapObj}', - rule: async (): Promise> => executable.properties.sourceFileMap, + rule: async (): Promise> => + Object.assign({}, executable.properties.sourceFileMap, debugConfigData.launchSourceFileMap), }, ]; - const debugConfig = await resolveVariablesAsync(debugConfigTemplate, varToResolve); + const debugConfig = await resolveVariablesAsync(debugConfigData.template, varToResolve); // we dont know better: https://github.com/Microsoft/vscode/issues/70125 const magicValueKey = 'magic variable 🤦🏼‍';