diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index d39add02215..f4c1b144ae0 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -102,7 +102,7 @@ export class ExtHostAPIImplementation { const extHostDocuments = col.define(ExtHostContext.ExtHostDocuments).set(new ExtHostDocuments(threadService)); const extHostEditors = col.define(ExtHostContext.ExtHostEditors).set(new ExtHostEditors(threadService, extHostDocuments)); const extHostCommands = col.define(ExtHostContext.ExtHostCommands).set(new ExtHostCommands(threadService, extHostEditors)); - const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set(new ExtHostConfiguration(threadService)); + const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set(new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration))); const extHostDiagnostics = col.define(ExtHostContext.ExtHostDiagnostics).set(new ExtHostDiagnostics(threadService)); const languageFeatures = col.define(ExtHostContext.ExtHostLanguageFeatures).set(new ExtHostLanguageFeatures(threadService, extHostDocuments, extHostCommands, extHostDiagnostics)); const extHostFileSystemEvent = col.define(ExtHostContext.ExtHostFileSystemEventService).set(new ExtHostFileSystemEventService()); diff --git a/src/vs/workbench/api/node/extHostConfiguration.ts b/src/vs/workbench/api/node/extHostConfiguration.ts index e1d52fbfcd1..896f81c5a30 100644 --- a/src/vs/workbench/api/node/extHostConfiguration.ts +++ b/src/vs/workbench/api/node/extHostConfiguration.ts @@ -8,8 +8,7 @@ import {mixin} from 'vs/base/common/objects'; import {illegalState} from 'vs/base/common/errors'; import Event, {Emitter} from 'vs/base/common/event'; import {WorkspaceConfiguration} from 'vscode'; -import {ExtHostConfigurationShape, MainContext, MainThreadConfigurationShape} from './extHost.protocol'; -import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; +import {ExtHostConfigurationShape, MainThreadConfigurationShape} from './extHost.protocol'; import {ConfigurationTarget, ConfigurationEditingResult} from 'vs/workbench/services/configuration/common/configurationEditing'; export class ExtHostConfiguration extends ExtHostConfigurationShape { @@ -17,12 +16,11 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape { private _proxy: MainThreadConfigurationShape; private _hasConfig: boolean; private _config: any; - private _onDidChangeConfiguration: Emitter; + private _onDidChangeConfiguration = new Emitter(); - constructor(threadService: IThreadService) { + constructor(proxy: MainThreadConfigurationShape) { super(); - this._proxy = threadService.get(MainContext.MainThreadConfiguration); - this._onDidChangeConfiguration = new Emitter(); + this._proxy = proxy; } get onDidChangeConfiguration(): Event { @@ -56,6 +54,7 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape { return result; }, update: (key: string, value: any, global: boolean) => { + key = section ? `${section}.${key}` : key; const target = global ? ConfigurationTarget.USER : ConfigurationTarget.WORKSPACE; return this._proxy.$updateConfigurationOption(target, key, value).then(value => { if (value !== ConfigurationEditingResult.OK) { diff --git a/src/vs/workbench/test/node/api/extHostConfiguration.test.ts b/src/vs/workbench/test/node/api/extHostConfiguration.test.ts new file mode 100644 index 00000000000..c44d719e003 --- /dev/null +++ b/src/vs/workbench/test/node/api/extHostConfiguration.test.ts @@ -0,0 +1,70 @@ +/*--------------------------------------------------------------------------------------------- + * 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 {ExtHostConfiguration} from 'vs/workbench/api/node/extHostConfiguration'; +import {MainThreadConfigurationShape} from 'vs/workbench/api/node/extHost.protocol'; +import {TPromise} from 'vs/base/common/winjs.base'; +import {ConfigurationTarget, ConfigurationEditingResult} from 'vs/workbench/services/configuration/common/configurationEditing'; + +suite('ExtHostConfiguration', function () { + + class RecordingShape extends MainThreadConfigurationShape { + lastArgs: [ConfigurationTarget, string, any]; + $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): TPromise { + this.lastArgs = [target, key, value]; + return TPromise.as(ConfigurationEditingResult.OK); + } + }; + + function createExtHostConfiguration(data: any = {}, shape?: MainThreadConfigurationShape) { + if (!shape) { + shape = new class extends MainThreadConfigurationShape { }; + } + const result = new ExtHostConfiguration(shape); + result.$acceptConfigurationChanged(data); + return result; + } + + test('check illegal state', function () { + assert.throws(() => new ExtHostConfiguration(new class extends MainThreadConfigurationShape { }).getConfiguration('foo')); + }); + + test('udate / section to key', function () { + + const shape = new RecordingShape(); + const allConfig = createExtHostConfiguration({ foo: { bar: 1, far: 2 } }, shape); + + let config = allConfig.getConfiguration('foo'); + config.update('bar', 42, true); + + assert.equal(shape.lastArgs[0], ConfigurationEditingResult.OK); + assert.equal(shape.lastArgs[1], 'foo.bar'); + assert.equal(shape.lastArgs[2], 42); + + config = allConfig.getConfiguration(''); + config.update('bar', 42, true); + assert.equal(shape.lastArgs[1], 'bar'); + + config.update('foo.bar', 42, true); + assert.equal(shape.lastArgs[1], 'foo.bar'); + }); + + test('update / error-state not OK', function () { + + const shape = new class extends MainThreadConfigurationShape { + $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): TPromise { + return TPromise.as(ConfigurationEditingResult.ERROR_UNKNOWN_KEY); // something !== OK + } + }; + + return createExtHostConfiguration({}, shape) + .getConfiguration('') + .update('', true, false) + .then(() => assert.ok(false), err => { /* expecting rejection */}); + }); +});