-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8784 from DonJayamanne/replaceSettingsInDebugger
replace settings variables in debugger config #8042
- Loading branch information
Showing
9 changed files
with
173 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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 * as Types from 'vs/base/common/types'; | ||
import { SystemVariables } from './systemVariables'; | ||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; | ||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; | ||
import { IWorkspaceContextService } from 'vs/workbench/services/workspace/common/contextService'; | ||
import URI from 'vs/base/common/uri'; | ||
|
||
export class ConfigVariables extends SystemVariables { | ||
constructor(private configurationService: IConfigurationService, editorService: IWorkbenchEditorService, contextService: IWorkspaceContextService, workspaceRoot: URI = null, envVariables: { [key: string]: string } = process.env) { | ||
super(editorService, contextService, workspaceRoot, envVariables); | ||
} | ||
|
||
protected resolveString(value: string): string { | ||
value = super.resolveString(value); | ||
|
||
let regexp = /\$\{config\.(.*?)\}/g; | ||
return value.replace(regexp, (match: string, name: string) => { | ||
let config = this.configurationService.getConfiguration(); | ||
let newValue = new Function('_', 'try {return _.' + name + ';} catch (ex) { return "";}')(config); | ||
return Types.isString(newValue) ? newValue : ''; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/vs/workbench/parts/lib/test/node/configVariables.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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 * as assert from 'assert'; | ||
import URI from 'vs/base/common/uri'; | ||
import * as Platform from 'vs/base/common/platform'; | ||
import { ConfigVariables } from 'vs/workbench/parts/lib/node/configVariables'; | ||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; | ||
import {TPromise} from 'vs/base/common/winjs.base'; | ||
|
||
suite('ConfigVariables tests', () => { | ||
test('ConfigVariables: substitute one', () => { | ||
let configurationService: IConfigurationService; | ||
configurationService = new MockConfigurationService({ | ||
editor: { | ||
fontFamily: 'foo' | ||
}, | ||
terminal: { | ||
integrated: { | ||
fontFamily: 'bar' | ||
} | ||
} | ||
}); | ||
|
||
let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation')); | ||
assert.strictEqual(systemVariables.resolve('abc ${config.editor.fontFamily} xyz'), 'abc foo xyz'); | ||
}); | ||
|
||
test('ConfigVariables: substitute many', () => { | ||
let configurationService: IConfigurationService; | ||
configurationService = new MockConfigurationService({ | ||
editor: { | ||
fontFamily: 'foo' | ||
}, | ||
terminal: { | ||
integrated: { | ||
fontFamily: 'bar' | ||
} | ||
} | ||
}); | ||
|
||
let systemVariables: ConfigVariables = new ConfigVariables(configurationService, null, null, URI.parse('file:///VSCode/workspaceLocation')); | ||
assert.strictEqual(systemVariables.resolve('abc ${config.editor.fontFamily} ${config.terminal.integrated.fontFamily} xyz'), 'abc foo bar xyz'); | ||
}); | ||
test('SystemVariables: substitute one env variable', () => { | ||
let configurationService: IConfigurationService; | ||
configurationService = new MockConfigurationService({ | ||
editor: { | ||
fontFamily: 'foo' | ||
}, | ||
terminal: { | ||
integrated: { | ||
fontFamily: 'bar' | ||
} | ||
} | ||
}); | ||
|
||
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); | ||
if (Platform.isWindows) { | ||
assert.strictEqual(systemVariables.resolve('abc ${config.editor.fontFamily} ${workspaceRoot} ${env.key1} xyz'), 'abc foo \\VSCode\\workspaceLocation Value for Key1 xyz'); | ||
} else { | ||
assert.strictEqual(systemVariables.resolve('abc ${config.editor.fontFamily} ${workspaceRoot} ${env.key1} xyz'), 'abc foo /VSCode/workspaceLocation Value for Key1 xyz'); | ||
} | ||
}); | ||
|
||
test('SystemVariables: substitute many env variable', () => { | ||
let configurationService: IConfigurationService; | ||
configurationService = new MockConfigurationService({ | ||
editor: { | ||
fontFamily: 'foo' | ||
}, | ||
terminal: { | ||
integrated: { | ||
fontFamily: 'bar' | ||
} | ||
} | ||
}); | ||
|
||
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); | ||
if (Platform.isWindows) { | ||
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 { | ||
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'); | ||
} | ||
}); | ||
}); | ||
|
||
class MockConfigurationService implements IConfigurationService { | ||
public serviceId = IConfigurationService; | ||
public constructor(private configuration: any = {}) { } | ||
public loadConfiguration<T>(section?: string): TPromise<T> { return TPromise.as(this.getConfiguration()); } | ||
public getConfiguration(): any { return this.configuration; } | ||
public hasWorkspaceConfiguration(): boolean { return false; } | ||
public onDidUpdateConfiguration() { return { dispose() { } }; } | ||
public setUserConfiguration(key: any, value: any): Thenable<void> { return TPromise.as(null); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters