-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace settings variables in debugger config #8042 #8784
Merged
isidorn
merged 2 commits into
microsoft:master
from
DonJayamanne:replaceSettingsInDebugger
Jul 19, 2016
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regexp should have 'config' not 'settings' to allign with other places where we have replacments. |
||
let regexp = /\$\{settings\.(.*?)\}/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 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome work 👍 |
||
* 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 ${settings.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 ${settings.editor.fontFamily} ${settings.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 ${settings.editor.fontFamily} ${workspaceRoot} ${env.key1} xyz'), 'abc foo \\VSCode\\workspaceLocation Value for Key1 xyz'); | ||
} else { | ||
assert.strictEqual(systemVariables.resolve('abc ${settings.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('${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'); | ||
} 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'); | ||
} | ||
}); | ||
}); | ||
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will probably throw an exception if you open the no-folder workspace.
That is the reason why I originally check for this.contextService.getWorkspace(), I think you need to re-introduce that check.