提交 468ea776 编写于 作者: J Johannes Rieken

Revert "undo update change for now, #1396"

This reverts commit 83053afc.
上级 909d4952
......@@ -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
......
......@@ -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);
}
};
......
......@@ -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<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 */});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册