From d452f8d21707a9d4291cb21f47e02ff3798c1917 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 28 Jun 2016 23:04:30 +1000 Subject: [PATCH] changes to replace settings variables in launch config #8042 --- src/vs/base/common/parsers.ts | 8 ++++---- .../debug/node/debugConfigurationManager.ts | 9 +++++++++ .../parts/lib/node/settingsVariables.ts | 20 +++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/vs/workbench/parts/lib/node/settingsVariables.ts diff --git a/src/vs/base/common/parsers.ts b/src/vs/base/common/parsers.ts index 9bcfa66446a..fb34ec93e7f 100644 --- a/src/vs/base/common/parsers.ts +++ b/src/vs/base/common/parsers.ts @@ -130,7 +130,7 @@ export abstract class AbstractSystemVariables implements ISystemVariables { public resolve(value: IStringDictionary>): IStringDictionary>; public resolve(value: any): any { if (Types.isString(value)) { - return this.__resolveString(value); + return this.resolveString(value); } else if (Types.isArray(value)) { return this.__resolveArray(value); } else if (Types.isObject(value)) { @@ -143,7 +143,7 @@ export abstract class AbstractSystemVariables implements ISystemVariables { resolveAny(value: T): T; resolveAny(value: any): any { if (Types.isString(value)) { - return this.__resolveString(value); + return this.resolveString(value); } else if (Types.isArray(value)) { return this.__resolveAnyArray(value); } else if (Types.isObject(value)) { @@ -153,7 +153,7 @@ export abstract class AbstractSystemVariables implements ISystemVariables { return value; } - private __resolveString(value: string): string { + protected resolveString(value: string): string { let regexp = /\$\{(.*?)\}/g; return value.replace(regexp, (match: string, name: string) => { let newValue = (this)[name]; @@ -185,7 +185,7 @@ export abstract class AbstractSystemVariables implements ISystemVariables { } private __resolveArray(value: string[]): string[] { - return value.map(s => this.__resolveString(s)); + return value.map(s => this.resolveString(s)); } private __resolveAnyArray(value: T[]): T[]; diff --git a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts index 6d2be639db5..7ea04864882 100644 --- a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts @@ -30,6 +30,7 @@ import { Adapter } from 'vs/workbench/parts/debug/node/debugAdapter'; import { IWorkspaceContextService } from 'vs/workbench/services/workspace/common/contextService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService'; +import { SettingsVariables } from 'vs/workbench/parts/lib/node/settingsVariables'; // debuggers extension point @@ -155,6 +156,7 @@ export class ConfigurationManager implements debug.IConfigurationManager { public configuration: debug.IConfig; private systemVariables: SystemVariables; + private settingsVariables: SettingsVariables; private adapters: Adapter[]; private allModeIdsForBreakpoints: { [key: string]: boolean }; private _onDidConfigurationChange: Emitter; @@ -171,6 +173,7 @@ export class ConfigurationManager implements debug.IConfigurationManager { ) { this._onDidConfigurationChange = new Emitter(); this.systemVariables = this.contextService.getWorkspace() ? new SystemVariables(this.editorService, this.contextService) : null; + this.settingsVariables = new SettingsVariables(this.configurationService.getConfiguration()); this.setConfiguration(configName); this.adapters = []; this.registerListeners(); @@ -326,6 +329,12 @@ export class ConfigurationManager implements debug.IConfigurationManager { this.configuration[key] = this.systemVariables.resolveAny(this.configuration[key]); }); } + // massage configuration attributes - substitute settings (from settings.json) variables. + if (this.systemVariables) { + Object.keys(this.configuration).forEach(key => { + this.configuration[key] = this.settingsVariables.resolveAny(this.configuration[key]); + }); + } } }).then(() => this._onDidConfigurationChange.fire(this.configurationName)); } diff --git a/src/vs/workbench/parts/lib/node/settingsVariables.ts b/src/vs/workbench/parts/lib/node/settingsVariables.ts new file mode 100644 index 00000000000..c25048c939d --- /dev/null +++ b/src/vs/workbench/parts/lib/node/settingsVariables.ts @@ -0,0 +1,20 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { AbstractSystemVariables } from 'vs/base/common/parsers'; + +export class SettingsVariables extends AbstractSystemVariables { + constructor(private configuration:any) { + super(); + } + + protected resolveString(value: string): string { + let regexp = /\${settings.(.+)}/g; + return value.replace(regexp, (match: string, name: string) => { + return new Function('_', 'return _.' + name)(this.configuration); + }); + } +} \ No newline at end of file