mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-10 16:58:55 -05:00
Simplify configuration resolver (#13051)
This commit is contained in:
committed by
chrmarti
parent
1459824cad
commit
5010ee2df2
5
npm-shrinkwrap.json
generated
5
npm-shrinkwrap.json
generated
@@ -302,11 +302,6 @@
|
||||
"from": "object.omit@>=2.0.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/object.omit/-/object.omit-2.0.0.tgz"
|
||||
},
|
||||
"objectpath": {
|
||||
"version": "1.2.1",
|
||||
"from": "objectpath@>=1.2.1 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/objectpath/-/objectpath-1.2.1.tgz"
|
||||
},
|
||||
"oniguruma": {
|
||||
"version": "6.1.1",
|
||||
"from": "oniguruma@>=6.0.1 <7.0.0",
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
"iconv-lite": "0.4.13",
|
||||
"minimist": "1.2.0",
|
||||
"native-keymap": "0.2.0",
|
||||
"objectpath": "^1.2.1",
|
||||
"pty.js": "https://github.com/Tyriar/pty.js/tarball/fffbf86eb9e8051b5b2be4ba9c7b07faa018ce8d",
|
||||
"semver": "4.3.6",
|
||||
"vscode-debugprotocol": "1.13.0",
|
||||
|
||||
8
src/typings/objectpath.d.ts
vendored
8
src/typings/objectpath.d.ts
vendored
@@ -1,8 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module "objectpath" {
|
||||
export function parse(path: string): string[];
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as ObjectPath from 'objectpath';
|
||||
import nls = require('vs/nls');
|
||||
import * as paths from 'vs/base/common/paths';
|
||||
import * as types from 'vs/base/common/types';
|
||||
@@ -136,7 +135,7 @@ export class ConfigurationResolverService implements IConfigurationResolverServi
|
||||
let config = this.configurationService.getConfiguration();
|
||||
let newValue: any;
|
||||
try {
|
||||
const keys: string[] = ObjectPath.parse(name);
|
||||
const keys: string[] = name.split('.');
|
||||
if (!keys || keys.length <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -209,35 +209,7 @@ suite('Configuration Resolver Service', () => {
|
||||
});
|
||||
|
||||
let service = new ConfigurationResolverService(uri.parse('file:///VSCode/workspaceLocation'), envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService);
|
||||
assert.strictEqual(service.resolve('abc ${config.editor.fontFamily} ${config.editor.lineNumbers} ${config.editor.insertSpaces} ${config.json.schemas[0].fileMatch[1]} xyz'), 'abc foo 123 false {{/myOtherfile}} xyz');
|
||||
});
|
||||
|
||||
test('configuration variables using bracket accessor', () => {
|
||||
let configurationService: IConfigurationService;
|
||||
configurationService = new MockConfigurationService({
|
||||
editor: {
|
||||
fontFamily: 'foo'
|
||||
}
|
||||
});
|
||||
|
||||
let service = new ConfigurationResolverService(uri.parse('file:///VSCode/workspaceLocation'), envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService);
|
||||
assert.strictEqual(service.resolve("abc ${config.editor['fontFamily']} xyz"), 'abc foo xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config["editor"].fontFamily} xyz'), 'abc foo xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config["editor"]["fontFamily"]} xyz'), 'abc foo xyz');
|
||||
});
|
||||
|
||||
test('configuration variables with invalid accessor', () => {
|
||||
let configurationService: IConfigurationService;
|
||||
configurationService = new MockConfigurationService({
|
||||
editor: {
|
||||
fontFamily: 'foo'
|
||||
}
|
||||
});
|
||||
|
||||
let service = new ConfigurationResolverService(uri.parse('file:///VSCode/workspaceLocation'), envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService);
|
||||
assert.strictEqual(service.resolve("abc ${config.} xyz"), 'abc ${config.} xyz');
|
||||
assert.strictEqual(service.resolve("abc ${config.editor..fontFamily} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve("abc ${config.editor.none.none2} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.editor.fontFamily} ${config.editor.lineNumbers} ${config.editor.insertSpaces} xyz'), 'abc foo 123 false xyz');
|
||||
});
|
||||
|
||||
test('configuration should not evaluate Javascript', () => {
|
||||
@@ -249,7 +221,7 @@ suite('Configuration Resolver Service', () => {
|
||||
});
|
||||
|
||||
let service = new ConfigurationResolverService(uri.parse('file:///VSCode/workspaceLocation'), envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService);
|
||||
assert.strictEqual(service.resolve("abc ${config.editor['abc'.substr(0)]} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.editor[\'abc\'.substr(0)]} xyz'), 'abc xyz');
|
||||
});
|
||||
|
||||
test('uses empty string as fallback', () => {
|
||||
@@ -259,10 +231,10 @@ suite('Configuration Resolver Service', () => {
|
||||
});
|
||||
|
||||
let service = new ConfigurationResolverService(uri.parse('file:///VSCode/workspaceLocation'), envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService);
|
||||
assert.strictEqual(service.resolve("abc ${config.editor.abc} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve("abc ${config.editor.abc.def} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve("abc ${config.panel} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve("abc ${config.panel.abc} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.editor.abc} xyz'), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.editor.abc.def} xyz'), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.panel} xyz'), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.panel.abc} xyz'), 'abc xyz');
|
||||
});
|
||||
|
||||
test('is restricted to own properties', () => {
|
||||
@@ -272,8 +244,22 @@ suite('Configuration Resolver Service', () => {
|
||||
});
|
||||
|
||||
let service = new ConfigurationResolverService(uri.parse('file:///VSCode/workspaceLocation'), envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService);
|
||||
assert.strictEqual(service.resolve("abc ${config.editor.__proto__} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve("abc ${config.editor.toString} xyz"), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.editor.__proto__} xyz'), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.editor.toString} xyz'), 'abc xyz');
|
||||
});
|
||||
|
||||
test('configuration variables with invalid accessor', () => {
|
||||
let configurationService: IConfigurationService;
|
||||
configurationService = new MockConfigurationService({
|
||||
editor: {
|
||||
fontFamily: 'foo'
|
||||
}
|
||||
});
|
||||
|
||||
let service = new ConfigurationResolverService(uri.parse('file:///VSCode/workspaceLocation'), envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService);
|
||||
assert.strictEqual(service.resolve('abc ${config.} xyz'), 'abc ${config.} xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.editor..fontFamily} xyz'), 'abc xyz');
|
||||
assert.strictEqual(service.resolve('abc ${config.editor.none.none2} xyz'), 'abc xyz');
|
||||
});
|
||||
|
||||
test('interactive variable simple', () => {
|
||||
|
||||
Reference in New Issue
Block a user