mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-30 03:09:05 +01:00
Merge pull request #28858 from Microsoft/sandy081/adoptExtHostConfiguration
Adopt ext host to use configuration tree data
This commit is contained in:
@@ -26,7 +26,7 @@ export class MainThreadConfiguration extends MainThreadConfigurationShape {
|
||||
const proxy = threadService.get(ExtHostContext.ExtHostConfiguration);
|
||||
|
||||
this._toDispose = configurationService.onDidUpdateConfiguration(() => {
|
||||
proxy.$acceptConfigurationChanged(configurationService.values());
|
||||
proxy.$acceptConfigurationChanged(configurationService.getConfigurationData());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
|
||||
import { ITextSource } from 'vs/editor/common/model/textSource';
|
||||
|
||||
import { ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
|
||||
import { IConfigurationValues } from 'vs/platform/configuration/common/configuration';
|
||||
import { IConfigurationData } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
import { IPickOpenEntry, IPickOptions } from 'vs/platform/quickOpen/common/quickOpen';
|
||||
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
@@ -67,7 +67,7 @@ export interface IInitData {
|
||||
environment: IEnvironment;
|
||||
workspace: IWorkspaceData;
|
||||
extensions: IExtensionDescription[];
|
||||
configuration: IConfigurationValues;
|
||||
configuration: IConfigurationData<any>;
|
||||
telemetryInfo: ITelemetryInfo;
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ export abstract class ExtHostCommandsShape {
|
||||
}
|
||||
|
||||
export abstract class ExtHostConfigurationShape {
|
||||
$acceptConfigurationChanged(values: IConfigurationValues) { throw ni(); }
|
||||
$acceptConfigurationChanged(data: IConfigurationData<any>) { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class ExtHostDiagnosticsShape {
|
||||
|
||||
@@ -8,9 +8,8 @@ import { mixin } from 'vs/base/common/objects';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { WorkspaceConfiguration } from 'vscode';
|
||||
import { ExtHostConfigurationShape, MainThreadConfigurationShape } from './extHost.protocol';
|
||||
import { IConfigurationValues } from 'vs/platform/configuration/common/configuration';
|
||||
import { IConfigurationData, Configuration } from 'vs/platform/configuration/common/configuration';
|
||||
import { ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
|
||||
import { toValuesTree } from 'vs/platform/configuration/common/model';
|
||||
|
||||
function lookUp(tree: any, key: string) {
|
||||
if (key) {
|
||||
@@ -23,51 +22,41 @@ function lookUp(tree: any, key: string) {
|
||||
}
|
||||
}
|
||||
|
||||
interface UsefulConfiguration {
|
||||
data: IConfigurationValues;
|
||||
valueTree: any;
|
||||
}
|
||||
|
||||
function createUsefulConfiguration(data: IConfigurationValues): { data: IConfigurationValues, valueTree: any } {
|
||||
const valueMap: { [key: string]: any } = Object.create(null);
|
||||
for (let key in data) {
|
||||
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
||||
valueMap[key] = data[key].value;
|
||||
}
|
||||
}
|
||||
const valueTree = toValuesTree(valueMap, message => console.error(`Conflict in configuration settings: ${message}`));
|
||||
return {
|
||||
data,
|
||||
valueTree
|
||||
};
|
||||
}
|
||||
|
||||
export class ExtHostConfiguration extends ExtHostConfigurationShape {
|
||||
|
||||
private _onDidChangeConfiguration = new Emitter<void>();
|
||||
private _proxy: MainThreadConfigurationShape;
|
||||
private _configuration: UsefulConfiguration;
|
||||
private _data: IConfigurationData<any>;
|
||||
private _configuration: Configuration<any>;
|
||||
|
||||
constructor(proxy: MainThreadConfigurationShape, data: IConfigurationValues) {
|
||||
constructor(proxy: MainThreadConfigurationShape, data: IConfigurationData<any>) {
|
||||
super();
|
||||
this._proxy = proxy;
|
||||
this._configuration = createUsefulConfiguration(data);
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
get onDidChangeConfiguration(): Event<void> {
|
||||
return this._onDidChangeConfiguration && this._onDidChangeConfiguration.event;
|
||||
}
|
||||
|
||||
public $acceptConfigurationChanged(data: IConfigurationValues) {
|
||||
this._configuration = createUsefulConfiguration(data);
|
||||
public $acceptConfigurationChanged(data: IConfigurationData<any>) {
|
||||
this._configuration = null;
|
||||
this._data = data;
|
||||
this._onDidChangeConfiguration.fire(undefined);
|
||||
}
|
||||
|
||||
private get configuration(): Configuration<any> {
|
||||
if (!this._configuration) {
|
||||
this._configuration = Configuration.parse(this._data);
|
||||
}
|
||||
return this._configuration;
|
||||
}
|
||||
|
||||
public getConfiguration(section?: string): WorkspaceConfiguration {
|
||||
|
||||
const config = section
|
||||
? lookUp(this._configuration.valueTree, section)
|
||||
: this._configuration.valueTree;
|
||||
? lookUp(this.configuration.getValue(), section)
|
||||
: this.configuration.getValue();
|
||||
|
||||
const result: WorkspaceConfiguration = {
|
||||
has(key: string): boolean {
|
||||
@@ -91,7 +80,7 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape {
|
||||
},
|
||||
inspect: <T>(key: string): { key: string; defaultValue?: T; globalValue?: T; workspaceValue?: T } => {
|
||||
key = section ? `${section}.${key}` : key;
|
||||
const config = this._configuration.data[key];
|
||||
const config = this.configuration.values()[key];
|
||||
if (config) {
|
||||
return {
|
||||
key,
|
||||
|
||||
@@ -290,7 +290,7 @@ export class ExtensionHostProcessWorker {
|
||||
},
|
||||
workspace: <IWorkspaceData>this.contextService.getWorkspace2(),
|
||||
extensions: extensionDescriptions,
|
||||
configuration: this.configurationService.values(),
|
||||
configuration: this.configurationService.getConfigurationData(),
|
||||
telemetryInfo
|
||||
};
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ 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 { IConfigurationValues, IConfigurationValue } from 'vs/platform/configuration/common/configuration';
|
||||
import { ConfigurationModel } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
suite('ExtHostConfiguration', function () {
|
||||
|
||||
@@ -22,25 +22,25 @@ suite('ExtHostConfiguration', function () {
|
||||
}
|
||||
};
|
||||
|
||||
function createExtHostConfiguration(data: IConfigurationValues = Object.create(null), shape?: MainThreadConfigurationShape) {
|
||||
function createExtHostConfiguration(contents: any = Object.create(null), shape?: MainThreadConfigurationShape) {
|
||||
if (!shape) {
|
||||
shape = new class extends MainThreadConfigurationShape { };
|
||||
}
|
||||
return new ExtHostConfiguration(shape, data);
|
||||
}
|
||||
|
||||
function createConfigurationValue<T>(value: T): IConfigurationValue<T> {
|
||||
return {
|
||||
value,
|
||||
default: value,
|
||||
user: undefined,
|
||||
workspace: undefined
|
||||
};
|
||||
return new ExtHostConfiguration(shape, {
|
||||
defaults: new ConfigurationModel(contents),
|
||||
user: new ConfigurationModel(contents),
|
||||
folders: Object.create(null),
|
||||
workspaceUri: void 0
|
||||
});
|
||||
}
|
||||
|
||||
test('getConfiguration fails regression test 1.7.1 -> 1.8 #15552', function () {
|
||||
const extHostConfig = createExtHostConfiguration({
|
||||
['search.exclude']: createConfigurationValue({ '**/node_modules': true })
|
||||
'search': {
|
||||
'exclude': {
|
||||
'**/node_modules': true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(extHostConfig.getConfiguration('search.exclude')['**/node_modules'], true);
|
||||
@@ -54,10 +54,14 @@ suite('ExtHostConfiguration', function () {
|
||||
test('has/get', function () {
|
||||
|
||||
const all = createExtHostConfiguration({
|
||||
['farboo.config0']: createConfigurationValue(true),
|
||||
['farboo.nested.config1']: createConfigurationValue(42),
|
||||
['farboo.nested.config2']: createConfigurationValue('Das Pferd frisst kein Reis.'),
|
||||
['farboo.config4']: createConfigurationValue('')
|
||||
'farboo': {
|
||||
'config0': true,
|
||||
'nested': {
|
||||
'config1': 42,
|
||||
'config2': 'Das Pferd frisst kein Reis.'
|
||||
},
|
||||
'config4': ''
|
||||
}
|
||||
});
|
||||
|
||||
const config = all.getConfiguration('farboo');
|
||||
@@ -80,8 +84,10 @@ suite('ExtHostConfiguration', function () {
|
||||
test('getConfiguration vs get', function () {
|
||||
|
||||
const all = createExtHostConfiguration({
|
||||
['farboo.config0']: createConfigurationValue(true),
|
||||
['farboo.config4']: createConfigurationValue(38)
|
||||
'farboo': {
|
||||
'config0': true,
|
||||
'config4': 38
|
||||
}
|
||||
});
|
||||
|
||||
let config = all.getConfiguration('farboo.config0');
|
||||
@@ -96,8 +102,10 @@ suite('ExtHostConfiguration', function () {
|
||||
test('getConfiguration vs get', function () {
|
||||
|
||||
const all = createExtHostConfiguration({
|
||||
['farboo.config0']: createConfigurationValue(true),
|
||||
['farboo.config4']: createConfigurationValue(38)
|
||||
'farboo': {
|
||||
'config0': true,
|
||||
'config4': 38
|
||||
}
|
||||
});
|
||||
|
||||
let config = all.getConfiguration('farboo.config0');
|
||||
@@ -111,7 +119,9 @@ suite('ExtHostConfiguration', function () {
|
||||
|
||||
test('name vs property', function () {
|
||||
const all = createExtHostConfiguration({
|
||||
['farboo.get']: createConfigurationValue('get-prop')
|
||||
'farboo': {
|
||||
'get': 'get-prop'
|
||||
}
|
||||
});
|
||||
const config = all.getConfiguration('farboo');
|
||||
|
||||
@@ -125,8 +135,10 @@ suite('ExtHostConfiguration', function () {
|
||||
|
||||
const shape = new RecordingShape();
|
||||
const allConfig = createExtHostConfiguration({
|
||||
['foo.bar']: createConfigurationValue(1),
|
||||
['foo.far']: createConfigurationValue(1)
|
||||
'foo': {
|
||||
'bar': 1,
|
||||
'far': 1
|
||||
}
|
||||
}, shape);
|
||||
|
||||
let config = allConfig.getConfiguration('foo');
|
||||
@@ -146,7 +158,9 @@ suite('ExtHostConfiguration', function () {
|
||||
test('update, what is #15834', function () {
|
||||
const shape = new RecordingShape();
|
||||
const allConfig = createExtHostConfiguration({
|
||||
['editor.formatOnSave']: createConfigurationValue(true)
|
||||
'editor': {
|
||||
'formatOnSave': true
|
||||
}
|
||||
}, shape);
|
||||
|
||||
allConfig.getConfiguration('editor').update('formatOnSave', { extensions: ['ts'] });
|
||||
@@ -154,28 +168,30 @@ suite('ExtHostConfiguration', function () {
|
||||
assert.deepEqual(shape.lastArgs[2], { extensions: ['ts'] });
|
||||
});
|
||||
|
||||
test('bogous data, #15834', function () {
|
||||
let oldLogger = console.error;
|
||||
let errorLogged = false;
|
||||
/*
|
||||
test('bogous data, #15834', function () {
|
||||
let oldLogger = console.error;
|
||||
let errorLogged = false;
|
||||
|
||||
// workaround until we have a proper logging story
|
||||
console.error = (message, args) => {
|
||||
errorLogged = true;
|
||||
};
|
||||
let allConfig;
|
||||
try {
|
||||
const shape = new RecordingShape();
|
||||
allConfig = createExtHostConfiguration({
|
||||
['editor.formatOnSave']: createConfigurationValue(true),
|
||||
['editor.formatOnSave.extensions']: createConfigurationValue(['ts'])
|
||||
}, shape);
|
||||
} finally {
|
||||
console.error = oldLogger;
|
||||
}
|
||||
assert.ok(errorLogged);
|
||||
assert.ok(allConfig.getConfiguration('').has('editor.formatOnSave'));
|
||||
assert.ok(!allConfig.getConfiguration('').has('editor.formatOnSave.extensions'));
|
||||
});
|
||||
// workaround until we have a proper logging story
|
||||
console.error = (message, args) => {
|
||||
errorLogged = true;
|
||||
};
|
||||
let allConfig;
|
||||
try {
|
||||
const shape = new RecordingShape();
|
||||
allConfig = createExtHostConfiguration({
|
||||
['editor.formatOnSave']: createConfigurationValue(true),
|
||||
['editor.formatOnSave.extensions']: createConfigurationValue(['ts'])
|
||||
}, shape);
|
||||
} finally {
|
||||
console.error = oldLogger;
|
||||
}
|
||||
assert.ok(errorLogged);
|
||||
assert.ok(allConfig.getConfiguration('').has('editor.formatOnSave'));
|
||||
assert.ok(!allConfig.getConfiguration('').has('editor.formatOnSave.extensions'));
|
||||
});
|
||||
*/
|
||||
|
||||
test('update/error-state not OK', function () {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user