Skip to content

Commit

Permalink
master: support advanced sourceMap from launch.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Mate Pek committed Nov 22, 2021
1 parent 0e8c8e4 commit 23ef810
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 23 additions & 10 deletions src/Configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.DebugConfiguration | null | 'extensionOnly'>(
'debug.configTemplate',
null,
Expand All @@ -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)
Expand Down Expand Up @@ -162,7 +162,7 @@ export class Configurations {
template,
);

return [template, 'fromLaunchJson'];
return { template, source: 'fromLaunchJson', launchSourceFileMap: wpLaunchConfigs[i].sourceFileMap };
}
}
}
Expand All @@ -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',
Expand All @@ -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, {
Expand All @@ -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');
Expand All @@ -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 {
Expand Down Expand Up @@ -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<string, string>;
};
15 changes: 8 additions & 7 deletions src/WorkspaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ export class WorkspaceManager implements vscode.Disposable {

const argsArrayFunc = async (): Promise<string[]> => 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 });
Expand All @@ -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',
Expand Down Expand Up @@ -449,11 +449,12 @@ export class WorkspaceManager implements vscode.Disposable {
},
{
resolve: '${sourceFileMapObj}',
rule: async (): Promise<Record<string, string>> => executable.properties.sourceFileMap,
rule: async (): Promise<Record<string, string>> =>
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 🤦🏼‍';
Expand Down

0 comments on commit 23ef810

Please sign in to comment.