Skip to content

Commit

Permalink
Revert "undo update change for now, #1396"
Browse files Browse the repository at this point in the history
This reverts commit 83053af.
  • Loading branch information
jrieken committed Sep 19, 2016
1 parent 909d495 commit 468ea77
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 39 deletions.
11 changes: 11 additions & 0 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;

/**
* Readable dictionary that backs this configuration.
* @readonly
Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/api/node/extHostConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
};

Expand Down
66 changes: 33 additions & 33 deletions src/vs/workbench/test/node/api/extHostConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {

Expand All @@ -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<any> {
// return TPromise.wrapError(<IConfigurationEditingError>{ code: ConfigurationEditingErrorCode.ERROR_UNKNOWN_KEY, message: 'Unknown Key' }); // something !== OK
// }
// };
const shape = new class extends MainThreadConfigurationShape {
$updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): TPromise<any> {
return TPromise.wrapError(<IConfigurationEditingError>{ 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 */});
});
});

0 comments on commit 468ea77

Please sign in to comment.