diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 347a59d1f50..ba90e871df0 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -2647,6 +2647,17 @@ declare namespace vscode { */ has(section: string): boolean; + /** + * Update a configuration value. A value can be changed for the current + * [workspace](#workspace.rootPath) only or globally for all instances of the + * editor. The updated configuration values are persisted. + * + * @param section Configuration name, supports _dotted_ names. + * @param value The new value. + * @param global When `true` changes the configuration value for all instances of the editor. + */ + update(section: string, value: any, global: boolean): Thenable; + /** * Readable dictionary that backs this configuration. * @readonly diff --git a/src/vs/workbench/api/node/extHostConfiguration.ts b/src/vs/workbench/api/node/extHostConfiguration.ts index 835ebf69510..760a4a7c9f7 100644 --- a/src/vs/workbench/api/node/extHostConfiguration.ts +++ b/src/vs/workbench/api/node/extHostConfiguration.ts @@ -9,7 +9,7 @@ import {illegalState} from 'vs/base/common/errors'; import Event, {Emitter} from 'vs/base/common/event'; import {WorkspaceConfiguration} from 'vscode'; import {ExtHostConfigurationShape, MainThreadConfigurationShape} from './extHost.protocol'; -// import {ConfigurationTarget} from 'vs/workbench/services/configuration/common/configurationEditing'; +import {ConfigurationTarget} from 'vs/workbench/services/configuration/common/configurationEditing'; export class ExtHostConfiguration extends ExtHostConfigurationShape { @@ -52,11 +52,11 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape { result = defaultValue; } 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); + }, + 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); } }; diff --git a/src/vs/workbench/test/node/api/extHostConfiguration.test.ts b/src/vs/workbench/test/node/api/extHostConfiguration.test.ts index 698c83097ab..f0dbfd633c3 100644 --- a/src/vs/workbench/test/node/api/extHostConfiguration.test.ts +++ b/src/vs/workbench/test/node/api/extHostConfiguration.test.ts @@ -9,7 +9,7 @@ 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/*, ConfigurationEditingErrorCode, IConfigurationEditingError*/} from 'vs/workbench/services/configuration/common/configurationEditing'; +import {ConfigurationTarget, ConfigurationEditingErrorCode, IConfigurationEditingError} from 'vs/workbench/services/configuration/common/configurationEditing'; suite('ExtHostConfiguration', function () { @@ -21,49 +21,49 @@ suite('ExtHostConfiguration', function () { } }; - // function createExtHostConfiguration(data: any = {}, shape?: MainThreadConfigurationShape) { - // if (!shape) { - // shape = new class extends MainThreadConfigurationShape { }; - // } - // const result = new ExtHostConfiguration(shape); - // result.$acceptConfigurationChanged(data); - // return result; - // } + 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 () { + test('udate / section to key', function () { - // const shape = new RecordingShape(); - // const allConfig = createExtHostConfiguration({ foo: { bar: 1, far: 2 } }, shape); + const shape = new RecordingShape(); + const allConfig = createExtHostConfiguration({ foo: { bar: 1, far: 2 } }, shape); - // let config = allConfig.getConfiguration('foo'); - // config.update('bar', 42, true); + let config = allConfig.getConfiguration('foo'); + config.update('bar', 42, true); - // assert.equal(shape.lastArgs[1], 'foo.bar'); - // assert.equal(shape.lastArgs[2], 42); + 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 = 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'); - // }); + config.update('foo.bar', 42, true); + assert.equal(shape.lastArgs[1], 'foo.bar'); + }); - // test('update / error-state not OK', function () { + test('update / error-state not OK', function () { - // const shape = new class extends MainThreadConfigurationShape { - // $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): TPromise { - // return TPromise.wrapError({ code: ConfigurationEditingErrorCode.ERROR_UNKNOWN_KEY, message: 'Unknown Key' }); // something !== OK - // } - // }; + const shape = new class extends MainThreadConfigurationShape { + $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): TPromise { + return TPromise.wrapError({ code: ConfigurationEditingErrorCode.ERROR_UNKNOWN_KEY, message: 'Unknown Key' }); // something !== OK + } + }; - // return createExtHostConfiguration({}, shape) - // .getConfiguration('') - // .update('', true, false) - // .then(() => assert.ok(false), err => { /* expecting rejection */}); - // }); + return createExtHostConfiguration({}, shape) + .getConfiguration('') + .update('', true, false) + .then(() => assert.ok(false), err => { /* expecting rejection */}); + }); });