reolved code review comments #8042

This commit is contained in:
Don Jayamanne 2016-07-11 08:39:29 +10:00
parent b8c4a030be
commit a81902c6ce
4 changed files with 9 additions and 9 deletions

View file

@ -168,7 +168,7 @@ export class ConfigurationManager implements debug.IConfigurationManager {
@IQuickOpenService private quickOpenService: IQuickOpenService, @IQuickOpenService private quickOpenService: IQuickOpenService,
@IKeybindingService private keybindingService: IKeybindingService @IKeybindingService private keybindingService: IKeybindingService
) { ) {
this.systemVariables = new ConfigVariables(this.configurationService, this.editorService, this.contextService); this.systemVariables = this.contextService.getWorkspace() ? new ConfigVariables(this.configurationService, this.editorService, this.contextService) : null;
this._onDidConfigurationChange = new Emitter<string>(); this._onDidConfigurationChange = new Emitter<string>();
this.setConfiguration(configName); this.setConfiguration(configName);
this.adapters = []; this.adapters = [];

View file

@ -19,7 +19,7 @@ export class ConfigVariables extends SystemVariables {
protected resolveString(value: string): string { protected resolveString(value: string): string {
value = super.resolveString(value); value = super.resolveString(value);
let regexp = /\$\{settings\.(.*?)\}/g; let regexp = /\$\{config\.(.*?)\}/g;
return value.replace(regexp, (match: string, name: string) => { return value.replace(regexp, (match: string, name: string) => {
let config = this.configurationService.getConfiguration(); let config = this.configurationService.getConfiguration();
let newValue = new Function('_', 'try {return _.' + name + ';} catch (ex) { return "";}')(config); let newValue = new Function('_', 'try {return _.' + name + ';} catch (ex) { return "";}')(config);

View file

@ -21,7 +21,7 @@ export class SystemVariables extends AbstractSystemVariables {
constructor(private editorService: IWorkbenchEditorService, contextService: IWorkspaceContextService, workspaceRoot: URI = null, envVariables: { [key: string]: string } = process.env) { constructor(private editorService: IWorkbenchEditorService, contextService: IWorkspaceContextService, workspaceRoot: URI = null, envVariables: { [key: string]: string } = process.env) {
super(); super();
let fsPath = ''; let fsPath = '';
if (workspaceRoot || contextService.getWorkspace()) { if (workspaceRoot || (contextService && contextService.getWorkspace())) {
fsPath = workspaceRoot ? workspaceRoot.fsPath : contextService.getWorkspace().resource.fsPath; fsPath = workspaceRoot ? workspaceRoot.fsPath : contextService.getWorkspace().resource.fsPath;
} }
this._workspaceRoot = Paths.normalize(fsPath, true); this._workspaceRoot = Paths.normalize(fsPath, true);

View file

@ -26,7 +26,7 @@ suite('ConfigVariables tests', () => {
}); });
let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation')); let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation'));
assert.strictEqual(systemVariables.resolve('abc ${settings.editor.fontFamily} xyz'), 'abc foo xyz'); assert.strictEqual(systemVariables.resolve('abc ${config.editor.fontFamily} xyz'), 'abc foo xyz');
}); });
test('ConfigVariables: substitute many', () => { test('ConfigVariables: substitute many', () => {
@ -43,7 +43,7 @@ suite('ConfigVariables tests', () => {
}); });
let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation')); let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation'));
assert.strictEqual(systemVariables.resolve('abc ${settings.editor.fontFamily} ${settings.terminal.integrated.fontFamily} xyz'), 'abc foo bar xyz'); assert.strictEqual(systemVariables.resolve('abc ${config.editor.fontFamily} ${config.terminal.integrated.fontFamily} xyz'), 'abc foo bar xyz');
}); });
test('SystemVariables: substitute one env variable', () => { test('SystemVariables: substitute one env variable', () => {
let configurationService: IConfigurationService; let configurationService: IConfigurationService;
@ -61,9 +61,9 @@ suite('ConfigVariables tests', () => {
let envVariables: { [key: string]: string } = { key1: 'Value for Key1', key2: 'Value for Key2' }; let envVariables: { [key: string]: string } = { key1: 'Value for Key1', key2: 'Value for Key2' };
let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation'), envVariables); let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation'), envVariables);
if (Platform.isWindows) { if (Platform.isWindows) {
assert.strictEqual(systemVariables.resolve('abc ${settings.editor.fontFamily} ${workspaceRoot} ${env.key1} xyz'), 'abc foo \\VSCode\\workspaceLocation Value for Key1 xyz'); assert.strictEqual(systemVariables.resolve('abc ${config.editor.fontFamily} ${workspaceRoot} ${env.key1} xyz'), 'abc foo \\VSCode\\workspaceLocation Value for Key1 xyz');
} else { } else {
assert.strictEqual(systemVariables.resolve('abc ${settings.editor.fontFamily} ${workspaceRoot} ${env.key1} xyz'), 'abc foo /VSCode/workspaceLocation Value for Key1 xyz'); assert.strictEqual(systemVariables.resolve('abc ${config.editor.fontFamily} ${workspaceRoot} ${env.key1} xyz'), 'abc foo /VSCode/workspaceLocation Value for Key1 xyz');
} }
}); });
@ -83,9 +83,9 @@ suite('ConfigVariables tests', () => {
let envVariables: { [key: string]: string } = { key1: 'Value for Key1', key2: 'Value for Key2' }; let envVariables: { [key: string]: string } = { key1: 'Value for Key1', key2: 'Value for Key2' };
let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation'), envVariables); let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation'), envVariables);
if (Platform.isWindows) { if (Platform.isWindows) {
assert.strictEqual(systemVariables.resolve('${settings.editor.fontFamily} ${settings.terminal.integrated.fontFamily} ${workspaceRoot} - ${workspaceRoot} ${env.key1} - ${env.key2}'), 'foo bar \\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation Value for Key1 - Value for Key2'); assert.strictEqual(systemVariables.resolve('${config.editor.fontFamily} ${config.terminal.integrated.fontFamily} ${workspaceRoot} - ${workspaceRoot} ${env.key1} - ${env.key2}'), 'foo bar \\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation Value for Key1 - Value for Key2');
} else { } else {
assert.strictEqual(systemVariables.resolve('${settings.editor.fontFamily} ${settings.terminal.integrated.fontFamily} ${workspaceRoot} - ${workspaceRoot} ${env.key1} - ${env.key2}'), 'foo bar /VSCode/workspaceLocation - /VSCode/workspaceLocation Value for Key1 - Value for Key2'); assert.strictEqual(systemVariables.resolve('${config.editor.fontFamily} ${config.terminal.integrated.fontFamily} ${workspaceRoot} - ${workspaceRoot} ${env.key1} - ${env.key2}'), 'foo bar /VSCode/workspaceLocation - /VSCode/workspaceLocation Value for Key1 - Value for Key2');
} }
}); });
}); });