From 5010ee2df271cb2363427bd8e59a36d490a5c605 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 30 Sep 2016 18:29:04 +0200 Subject: [PATCH] Simplify configuration resolver (#13051) --- npm-shrinkwrap.json | 5 -- package.json | 1 - src/typings/objectpath.d.ts | 8 --- .../node/configurationResolverService.ts | 3 +- .../node/configurationResolverService.test.ts | 58 +++++++------------ 5 files changed, 23 insertions(+), 52 deletions(-) delete mode 100644 src/typings/objectpath.d.ts diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 672e82239fe..c9f5485d0b8 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -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", diff --git a/package.json b/package.json index 6dfdee210ee..2169f9baa15 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/typings/objectpath.d.ts b/src/typings/objectpath.d.ts deleted file mode 100644 index 128b9bafe53..00000000000 --- a/src/typings/objectpath.d.ts +++ /dev/null @@ -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[]; -} diff --git a/src/vs/workbench/services/configurationResolver/node/configurationResolverService.ts b/src/vs/workbench/services/configurationResolver/node/configurationResolverService.ts index 5ecb4450e89..4ac59e9ad32 100644 --- a/src/vs/workbench/services/configurationResolver/node/configurationResolverService.ts +++ b/src/vs/workbench/services/configurationResolver/node/configurationResolverService.ts @@ -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 ''; } diff --git a/src/vs/workbench/services/configurationResolver/test/node/configurationResolverService.test.ts b/src/vs/workbench/services/configurationResolver/test/node/configurationResolverService.test.ts index c3cb269d392..943a7eb3ef5 100644 --- a/src/vs/workbench/services/configurationResolver/test/node/configurationResolverService.test.ts +++ b/src/vs/workbench/services/configurationResolver/test/node/configurationResolverService.test.ts @@ -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', () => {