From fbec8996f78a16483ce5f4a2ed426e95e5187ce9 Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 2 Jun 2016 19:22:27 +0200 Subject: [PATCH] debug: if an action variable is used multiple times in a launch config, the associated command should only be run once #7026 --- .../debug/node/debugConfigurationManager.ts | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts index 1d0d49687a0..2fc26c8046b 100644 --- a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts @@ -248,22 +248,35 @@ export class ConfigurationManager implements debug.IConfigurationManager { return TPromise.as(null); } - const factory = Object.keys(this.configuration).map(key => { - return () => { - if (typeof this.configuration[key] === 'string') { - const matches = /\${action.(.+)}/.exec(this.configuration[key]); - if (matches && matches.length === 2) { - const commandId = this.adapter.variables[matches[1]]; - if (!commandId) { - return TPromise.wrapError(nls.localize('interactiveVariableNotFound', "Adapter {0} does not contribute variable {1} that is specified in launch configuration.", this.adapter.type, matches[1])); - } else { - return this.keybindingService.executeCommand(commandId, this.configuration) - .then(result => result ? this.configuration[key] = result : this.configuration.silentlyAbort = true); - } + // We need a map from interactive variables to keys because we only want to trigger an action once per action - + // even though it might occure multiple times in configuration #7026. + const interactiveVariablesToKeys: { [key: string]: string[] } = {}; + Object.keys(this.configuration).forEach(key => { + if (typeof this.configuration[key] === 'string') { + const matches = /\${action.(.+)}/.exec(this.configuration[key]); + if (matches && matches.length === 2) { + const interactiveVariable = matches[1]; + if (!interactiveVariablesToKeys[interactiveVariable]) { + interactiveVariablesToKeys[interactiveVariable] = []; } + interactiveVariablesToKeys[interactiveVariable].push(key); } + } + }); - return TPromise.as(null); + const factory: { (): TPromise }[] = Object.keys(interactiveVariablesToKeys).map(interactiveVariable => { + return () => { + const commandId = this.adapter.variables ? this.adapter.variables[interactiveVariable] : null; + if (!commandId) { + return TPromise.wrapError(nls.localize('interactiveVariableNotFound', "Adapter {0} does not contribute variable {1} that is specified in launch configuration.", this.adapter.type, interactiveVariable)); + } else { + return this.keybindingService.executeCommand(commandId, this.configuration).then(result => { + if (!result) { + this.configuration.silentlyAbort = true; + } + interactiveVariablesToKeys[interactiveVariable].forEach(key => this.configuration[key] = result); + }); + } }; }); -- GitLab