mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-19 14:22:19 +01:00
@@ -70,6 +70,12 @@ export interface IConfigurationChangeEvent {
|
||||
affectsConfiguration(configuration: string, overrides?: IConfigurationOverrides): boolean;
|
||||
}
|
||||
|
||||
export interface IInspectValue<T> {
|
||||
readonly value?: T;
|
||||
readonly override?: T;
|
||||
readonly overrides?: { readonly identifiers: string[]; readonly value: T }[];
|
||||
}
|
||||
|
||||
export interface IConfigurationValue<T> {
|
||||
|
||||
readonly defaultValue?: T;
|
||||
@@ -83,14 +89,14 @@ export interface IConfigurationValue<T> {
|
||||
readonly policyValue?: T;
|
||||
readonly value?: T;
|
||||
|
||||
readonly default?: { value?: T; override?: T };
|
||||
readonly application?: { value?: T; override?: T };
|
||||
readonly user?: { value?: T; override?: T };
|
||||
readonly userLocal?: { value?: T; override?: T };
|
||||
readonly userRemote?: { value?: T; override?: T };
|
||||
readonly workspace?: { value?: T; override?: T };
|
||||
readonly workspaceFolder?: { value?: T; override?: T };
|
||||
readonly memory?: { value?: T; override?: T };
|
||||
readonly default?: IInspectValue<T>;
|
||||
readonly application?: IInspectValue<T>;
|
||||
readonly user?: IInspectValue<T>;
|
||||
readonly userLocal?: IInspectValue<T>;
|
||||
readonly userRemote?: IInspectValue<T>;
|
||||
readonly workspace?: IInspectValue<T>;
|
||||
readonly workspaceFolder?: IInspectValue<T>;
|
||||
readonly memory?: IInspectValue<T>;
|
||||
readonly policy?: { value?: T };
|
||||
|
||||
readonly overrideIdentifiers?: string[];
|
||||
|
||||
@@ -13,7 +13,7 @@ import * as objects from 'vs/base/common/objects';
|
||||
import { IExtUri } from 'vs/base/common/resources';
|
||||
import * as types from 'vs/base/common/types';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { addToValueTree, ConfigurationTarget, getConfigurationValue, IConfigurationChange, IConfigurationChangeEvent, IConfigurationCompareResult, IConfigurationData, IConfigurationModel, IConfigurationOverrides, IConfigurationUpdateOverrides, IConfigurationValue, IOverrides, removeFromValueTree, toValuesTree } from 'vs/platform/configuration/common/configuration';
|
||||
import { addToValueTree, ConfigurationTarget, getConfigurationValue, IConfigurationChange, IConfigurationChangeEvent, IConfigurationCompareResult, IConfigurationData, IConfigurationModel, IConfigurationOverrides, IConfigurationUpdateOverrides, IConfigurationValue, IInspectValue, IOverrides, removeFromValueTree, toValuesTree } from 'vs/platform/configuration/common/configuration';
|
||||
import { ConfigurationScope, Extensions, IConfigurationPropertySchema, IConfigurationRegistry, overrideIdentifiersFromKey, OVERRIDE_PROPERTY_REGEX } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { FileOperation, IFileService } from 'vs/platform/files/common/files';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
@@ -23,11 +23,7 @@ function freeze<T>(data: T): T {
|
||||
return Object.isFrozen(data) ? data : objects.deepFreeze(data);
|
||||
}
|
||||
|
||||
interface IInspectValue<V> {
|
||||
value?: V;
|
||||
override?: V;
|
||||
merged?: V;
|
||||
}
|
||||
type InspectValue<V> = IInspectValue<V> & { merged?: V };
|
||||
|
||||
export class ConfigurationModel implements IConfigurationModel {
|
||||
|
||||
@@ -82,11 +78,29 @@ export class ConfigurationModel implements IConfigurationModel {
|
||||
return section ? getConfigurationValue<any>(this.contents, section) : this.contents;
|
||||
}
|
||||
|
||||
inspect<V>(section: string | undefined, overrideIdentifier?: string | null): IInspectValue<V> {
|
||||
const value = this.rawConfiguration.getValue<V>(section);
|
||||
const override = overrideIdentifier ? this.rawConfiguration.getOverrideValue<V>(section, overrideIdentifier) : undefined;
|
||||
const merged = overrideIdentifier ? this.rawConfiguration.override(overrideIdentifier).getValue<V>(section) : value;
|
||||
return { value, override, merged };
|
||||
inspect<V>(section: string | undefined, overrideIdentifier?: string | null): InspectValue<V> {
|
||||
const that = this;
|
||||
return {
|
||||
get value() {
|
||||
return freeze(that.rawConfiguration.getValue<V>(section));
|
||||
},
|
||||
get override() {
|
||||
return overrideIdentifier ? freeze(that.rawConfiguration.getOverrideValue<V>(section, overrideIdentifier)) : undefined;
|
||||
},
|
||||
get merged() {
|
||||
return freeze(overrideIdentifier ? that.rawConfiguration.override(overrideIdentifier).getValue<V>(section) : that.rawConfiguration.getValue<V>(section));
|
||||
},
|
||||
get overrides() {
|
||||
const overrides: { readonly identifiers: string[]; readonly value: V }[] = [];
|
||||
for (const { contents, identifiers, keys } of that.rawConfiguration.overrides) {
|
||||
const value = new ConfigurationModel(contents, keys).getValue<V>(section);
|
||||
if (value !== undefined) {
|
||||
overrides.push({ identifiers, value });
|
||||
}
|
||||
}
|
||||
return overrides.length ? freeze(overrides) : undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getOverrideValue<V>(section: string | undefined, overrideIdentifier: string): V | undefined {
|
||||
@@ -504,19 +518,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return freeze(this._value);
|
||||
}
|
||||
|
||||
private inspect<V>(model: ConfigurationModel, section: string | undefined, overrideIdentifier?: string | null): IInspectValue<V> {
|
||||
const inspectValue = model.inspect<V>(section, overrideIdentifier);
|
||||
return {
|
||||
get value() { return freeze(inspectValue.value); },
|
||||
get override() { return freeze(inspectValue.override); },
|
||||
get merged() { return freeze(inspectValue.merged); }
|
||||
};
|
||||
private toInspectValue(inspectValue: IInspectValue<V> | undefined | null): IInspectValue<V> | undefined {
|
||||
return inspectValue?.value !== undefined || inspectValue?.override !== undefined || inspectValue?.overrides !== undefined ? inspectValue : undefined;
|
||||
}
|
||||
|
||||
private _defaultInspectValue: IInspectValue<V> | undefined;
|
||||
private get defaultInspectValue(): IInspectValue<V> {
|
||||
private _defaultInspectValue: InspectValue<V> | undefined;
|
||||
private get defaultInspectValue(): InspectValue<V> {
|
||||
if (!this._defaultInspectValue) {
|
||||
this._defaultInspectValue = this.inspect<V>(this.defaultConfiguration, this.key, this.overrides.overrideIdentifier);
|
||||
this._defaultInspectValue = this.defaultConfiguration.inspect<V>(this.key, this.overrides.overrideIdentifier);
|
||||
}
|
||||
return this._defaultInspectValue;
|
||||
}
|
||||
@@ -525,14 +534,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.defaultInspectValue.merged;
|
||||
}
|
||||
|
||||
get default(): { value?: V; override?: V } | undefined {
|
||||
return this.defaultInspectValue.value !== undefined || this.defaultInspectValue.override !== undefined ? { value: this.defaultInspectValue.value, override: this.defaultInspectValue.override } : undefined;
|
||||
get default(): IInspectValue<V> | undefined {
|
||||
return this.toInspectValue(this.defaultInspectValue);
|
||||
}
|
||||
|
||||
private _policyInspectValue: IInspectValue<V> | undefined | null;
|
||||
private get policyInspectValue(): IInspectValue<V> | null {
|
||||
private _policyInspectValue: InspectValue<V> | undefined | null;
|
||||
private get policyInspectValue(): InspectValue<V> | null {
|
||||
if (this._policyInspectValue === undefined) {
|
||||
this._policyInspectValue = this.policyConfiguration ? this.inspect<V>(this.policyConfiguration, this.key) : null;
|
||||
this._policyInspectValue = this.policyConfiguration ? this.policyConfiguration.inspect<V>(this.key) : null;
|
||||
}
|
||||
return this._policyInspectValue;
|
||||
}
|
||||
@@ -541,14 +550,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.policyInspectValue?.merged;
|
||||
}
|
||||
|
||||
get policy(): { value?: V; override?: V } | undefined {
|
||||
get policy(): IInspectValue<V> | undefined {
|
||||
return this.policyInspectValue?.value !== undefined ? { value: this.policyInspectValue.value } : undefined;
|
||||
}
|
||||
|
||||
private _applicationInspectValue: IInspectValue<V> | undefined | null;
|
||||
private get applicationInspectValue(): IInspectValue<V> | null {
|
||||
private _applicationInspectValue: InspectValue<V> | undefined | null;
|
||||
private get applicationInspectValue(): InspectValue<V> | null {
|
||||
if (this._applicationInspectValue === undefined) {
|
||||
this._applicationInspectValue = this.applicationConfiguration ? this.inspect<V>(this.applicationConfiguration, this.key) : null;
|
||||
this._applicationInspectValue = this.applicationConfiguration ? this.applicationConfiguration.inspect<V>(this.key) : null;
|
||||
}
|
||||
return this._applicationInspectValue;
|
||||
}
|
||||
@@ -557,14 +566,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.applicationInspectValue?.merged;
|
||||
}
|
||||
|
||||
get application(): { value?: V; override?: V } | undefined {
|
||||
return this.applicationInspectValue?.value !== undefined || this.applicationInspectValue?.override !== undefined ? { value: this.applicationInspectValue.value, override: this.applicationInspectValue.override } : undefined;
|
||||
get application(): IInspectValue<V> | undefined {
|
||||
return this.toInspectValue(this.applicationInspectValue);
|
||||
}
|
||||
|
||||
private _userInspectValue: IInspectValue<V> | undefined;
|
||||
private get userInspectValue(): IInspectValue<V> {
|
||||
private _userInspectValue: InspectValue<V> | undefined;
|
||||
private get userInspectValue(): InspectValue<V> {
|
||||
if (!this._userInspectValue) {
|
||||
this._userInspectValue = this.inspect<V>(this.userConfiguration, this.key, this.overrides.overrideIdentifier);
|
||||
this._userInspectValue = this.userConfiguration.inspect<V>(this.key, this.overrides.overrideIdentifier);
|
||||
}
|
||||
return this._userInspectValue;
|
||||
}
|
||||
@@ -573,14 +582,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.userInspectValue.merged;
|
||||
}
|
||||
|
||||
get user(): { value?: V; override?: V } | undefined {
|
||||
return this.userInspectValue.value !== undefined || this.userInspectValue.override !== undefined ? { value: this.userInspectValue.value, override: this.userInspectValue.override } : undefined;
|
||||
get user(): IInspectValue<V> | undefined {
|
||||
return this.toInspectValue(this.userInspectValue);
|
||||
}
|
||||
|
||||
private _userLocalInspectValue: IInspectValue<V> | undefined;
|
||||
private get userLocalInspectValue(): IInspectValue<V> {
|
||||
private _userLocalInspectValue: InspectValue<V> | undefined;
|
||||
private get userLocalInspectValue(): InspectValue<V> {
|
||||
if (!this._userLocalInspectValue) {
|
||||
this._userLocalInspectValue = this.inspect<V>(this.localUserConfiguration, this.key, this.overrides.overrideIdentifier);
|
||||
this._userLocalInspectValue = this.localUserConfiguration.inspect<V>(this.key, this.overrides.overrideIdentifier);
|
||||
}
|
||||
return this._userLocalInspectValue;
|
||||
}
|
||||
@@ -589,14 +598,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.userLocalInspectValue.merged;
|
||||
}
|
||||
|
||||
get userLocal(): { value?: V; override?: V } | undefined {
|
||||
return this.userLocalInspectValue.value !== undefined || this.userLocalInspectValue.override !== undefined ? { value: this.userLocalInspectValue.value, override: this.userLocalInspectValue.override } : undefined;
|
||||
get userLocal(): IInspectValue<V> | undefined {
|
||||
return this.toInspectValue(this.userLocalInspectValue);
|
||||
}
|
||||
|
||||
private _userRemoteInspectValue: IInspectValue<V> | undefined;
|
||||
private get userRemoteInspectValue(): IInspectValue<V> {
|
||||
private _userRemoteInspectValue: InspectValue<V> | undefined;
|
||||
private get userRemoteInspectValue(): InspectValue<V> {
|
||||
if (!this._userRemoteInspectValue) {
|
||||
this._userRemoteInspectValue = this.inspect<V>(this.remoteUserConfiguration, this.key, this.overrides.overrideIdentifier);
|
||||
this._userRemoteInspectValue = this.remoteUserConfiguration.inspect<V>(this.key, this.overrides.overrideIdentifier);
|
||||
}
|
||||
return this._userRemoteInspectValue;
|
||||
}
|
||||
@@ -605,14 +614,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.userRemoteInspectValue.merged;
|
||||
}
|
||||
|
||||
get userRemote(): { value?: V; override?: V } | undefined {
|
||||
return this.userRemoteInspectValue.value !== undefined || this.userRemoteInspectValue.override !== undefined ? { value: this.userRemoteInspectValue.value, override: this.userRemoteInspectValue.override } : undefined;
|
||||
get userRemote(): IInspectValue<V> | undefined {
|
||||
return this.toInspectValue(this.userRemoteInspectValue);
|
||||
}
|
||||
|
||||
private _workspaceInspectValue: IInspectValue<V> | undefined | null;
|
||||
private get workspaceInspectValue(): IInspectValue<V> | null {
|
||||
private _workspaceInspectValue: InspectValue<V> | undefined | null;
|
||||
private get workspaceInspectValue(): InspectValue<V> | null {
|
||||
if (this._workspaceInspectValue === undefined) {
|
||||
this._workspaceInspectValue = this.workspaceConfiguration ? this.inspect<V>(this.workspaceConfiguration, this.key, this.overrides.overrideIdentifier) : null;
|
||||
this._workspaceInspectValue = this.workspaceConfiguration ? this.workspaceConfiguration.inspect<V>(this.key, this.overrides.overrideIdentifier) : null;
|
||||
}
|
||||
return this._workspaceInspectValue;
|
||||
}
|
||||
@@ -621,14 +630,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.workspaceInspectValue?.merged;
|
||||
}
|
||||
|
||||
get workspace(): { value?: V; override?: V } | undefined {
|
||||
return this.workspaceInspectValue?.value !== undefined || this.workspaceInspectValue?.override !== undefined ? { value: this.workspaceInspectValue.value, override: this.workspaceInspectValue.override } : undefined;
|
||||
get workspace(): IInspectValue<V> | undefined {
|
||||
return this.toInspectValue(this.workspaceInspectValue);
|
||||
}
|
||||
|
||||
private _workspaceFolderInspectValue: IInspectValue<V> | undefined | null;
|
||||
private get workspaceFolderInspectValue(): IInspectValue<V> | null {
|
||||
private _workspaceFolderInspectValue: InspectValue<V> | undefined | null;
|
||||
private get workspaceFolderInspectValue(): InspectValue<V> | null {
|
||||
if (this._workspaceFolderInspectValue === undefined) {
|
||||
this._workspaceFolderInspectValue = this.folderConfigurationModel ? this.inspect<V>(this.folderConfigurationModel, this.key, this.overrides.overrideIdentifier) : null;
|
||||
this._workspaceFolderInspectValue = this.folderConfigurationModel ? this.folderConfigurationModel.inspect<V>(this.key, this.overrides.overrideIdentifier) : null;
|
||||
}
|
||||
return this._workspaceFolderInspectValue;
|
||||
}
|
||||
@@ -637,14 +646,14 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.workspaceFolderInspectValue?.merged;
|
||||
}
|
||||
|
||||
get workspaceFolder(): { value?: V; override?: V } | undefined {
|
||||
return this.workspaceFolderInspectValue?.value !== undefined || this.workspaceFolderInspectValue?.override !== undefined ? { value: this.workspaceFolderInspectValue.value, override: this.workspaceFolderInspectValue.override } : undefined;
|
||||
get workspaceFolder(): IInspectValue<V> | undefined {
|
||||
return this.toInspectValue(this.workspaceFolderInspectValue);
|
||||
}
|
||||
|
||||
private _memoryInspectValue: IInspectValue<V> | undefined;
|
||||
private get memoryInspectValue(): IInspectValue<V> {
|
||||
private _memoryInspectValue: InspectValue<V> | undefined;
|
||||
private get memoryInspectValue(): InspectValue<V> {
|
||||
if (this._memoryInspectValue === undefined) {
|
||||
this._memoryInspectValue = this.inspect<V>(this.memoryConfigurationModel, this.key, this.overrides.overrideIdentifier);
|
||||
this._memoryInspectValue = this.memoryConfigurationModel.inspect<V>(this.key, this.overrides.overrideIdentifier);
|
||||
}
|
||||
return this._memoryInspectValue;
|
||||
}
|
||||
@@ -653,8 +662,8 @@ class ConfigurationInspectValue<V> implements IConfigurationValue<V> {
|
||||
return this.memoryInspectValue.merged;
|
||||
}
|
||||
|
||||
get memory(): { value?: V; override?: V } | undefined {
|
||||
return this.memoryInspectValue.value !== undefined || this.memoryInspectValue.override !== undefined ? { value: this.memoryInspectValue.value, override: this.memoryInspectValue.override } : undefined;
|
||||
get memory(): IInspectValue<V> | undefined {
|
||||
return this.toInspectValue(this.memoryInspectValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -347,10 +347,10 @@ suite('ConfigurationModel', () => {
|
||||
test('inspect when raw is same', () => {
|
||||
const testObject = new ConfigurationModel({ 'a': 1, 'c': 1 }, ['a', 'c'], [{ identifiers: ['x', 'y'], contents: { 'a': 2, 'b': 1 }, keys: ['a'] }]);
|
||||
|
||||
assert.deepStrictEqual(testObject.inspect('a'), { value: 1, override: undefined, merged: 1 });
|
||||
assert.deepStrictEqual(testObject.inspect('a', 'x'), { value: 1, override: 2, merged: 2 });
|
||||
assert.deepStrictEqual(testObject.inspect('b', 'x'), { value: undefined, override: 1, merged: 1 });
|
||||
assert.deepStrictEqual(testObject.inspect('d'), { value: undefined, override: undefined, merged: undefined });
|
||||
assert.deepStrictEqual(testObject.inspect('a'), { value: 1, override: undefined, merged: 1, overrides: [{ identifiers: ['x', 'y'], value: 2 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('a', 'x'), { value: 1, override: 2, merged: 2, overrides: [{ identifiers: ['x', 'y'], value: 2 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('b', 'x'), { value: undefined, override: 1, merged: 1, overrides: [{ identifiers: ['x', 'y'], value: 1 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('d'), { value: undefined, override: undefined, merged: undefined, overrides: undefined });
|
||||
});
|
||||
|
||||
test('inspect when raw is not same', () => {
|
||||
@@ -365,11 +365,11 @@ suite('ConfigurationModel', () => {
|
||||
}
|
||||
}]);
|
||||
|
||||
assert.deepStrictEqual(testObject.inspect('a'), { value: 1, override: undefined, merged: 1 });
|
||||
assert.deepStrictEqual(testObject.inspect('a', 'x'), { value: 1, override: 2, merged: 2 });
|
||||
assert.deepStrictEqual(testObject.inspect('b', 'x'), { value: 2, override: 1, merged: 1 });
|
||||
assert.deepStrictEqual(testObject.inspect('d'), { value: 3, override: undefined, merged: 3 });
|
||||
assert.deepStrictEqual(testObject.inspect('e'), { value: undefined, override: undefined, merged: undefined });
|
||||
assert.deepStrictEqual(testObject.inspect('a'), { value: 1, override: undefined, merged: 1, overrides: [{ identifiers: ['x', 'y'], value: 2 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('a', 'x'), { value: 1, override: 2, merged: 2, overrides: [{ identifiers: ['x', 'y'], value: 2 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('b', 'x'), { value: 2, override: 1, merged: 1, overrides: [{ identifiers: ['x', 'y'], value: 1 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('d'), { value: 3, override: undefined, merged: 3, overrides: undefined });
|
||||
assert.deepStrictEqual(testObject.inspect('e'), { value: undefined, override: undefined, merged: undefined, overrides: undefined });
|
||||
});
|
||||
|
||||
test('inspect in merged configuration when raw is same', () => {
|
||||
@@ -377,11 +377,11 @@ suite('ConfigurationModel', () => {
|
||||
const target2 = new ConfigurationModel({ 'b': 3 }, ['b'], []);
|
||||
const testObject = target1.merge(target2);
|
||||
|
||||
assert.deepStrictEqual(testObject.inspect('a'), { value: 1, override: undefined, merged: 1 });
|
||||
assert.deepStrictEqual(testObject.inspect('a', 'x'), { value: 1, override: 2, merged: 2 });
|
||||
assert.deepStrictEqual(testObject.inspect('b'), { value: 3, override: undefined, merged: 3 });
|
||||
assert.deepStrictEqual(testObject.inspect('b', 'y'), { value: 3, override: undefined, merged: 3 });
|
||||
assert.deepStrictEqual(testObject.inspect('c'), { value: undefined, override: undefined, merged: undefined });
|
||||
assert.deepStrictEqual(testObject.inspect('a'), { value: 1, override: undefined, merged: 1, overrides: [{ identifiers: ['x', 'y'], value: 2 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('a', 'x'), { value: 1, override: 2, merged: 2, overrides: [{ identifiers: ['x', 'y'], value: 2 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('b'), { value: 3, override: undefined, merged: 3, overrides: undefined });
|
||||
assert.deepStrictEqual(testObject.inspect('b', 'y'), { value: 3, override: undefined, merged: 3, overrides: undefined });
|
||||
assert.deepStrictEqual(testObject.inspect('c'), { value: undefined, override: undefined, merged: undefined, overrides: undefined });
|
||||
});
|
||||
|
||||
test('inspect in merged configuration when raw is not same for one model', () => {
|
||||
@@ -397,11 +397,30 @@ suite('ConfigurationModel', () => {
|
||||
const target2 = new ConfigurationModel({ 'b': 3 }, ['b'], []);
|
||||
const testObject = target1.merge(target2);
|
||||
|
||||
assert.deepStrictEqual(testObject.inspect('a'), { value: 1, override: undefined, merged: 1 });
|
||||
assert.deepStrictEqual(testObject.inspect('a', 'x'), { value: 1, override: 2, merged: 2 });
|
||||
assert.deepStrictEqual(testObject.inspect('b'), { value: 3, override: undefined, merged: 3 });
|
||||
assert.deepStrictEqual(testObject.inspect('b', 'y'), { value: 3, override: 4, merged: 4 });
|
||||
assert.deepStrictEqual(testObject.inspect('c'), { value: 3, override: undefined, merged: 3 });
|
||||
assert.deepStrictEqual(testObject.inspect('a'), { value: 1, override: undefined, merged: 1, overrides: [{ identifiers: ['x', 'y'], value: 2 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('a', 'x'), { value: 1, override: 2, merged: 2, overrides: [{ identifiers: ['x', 'y'], value: 2 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('b'), { value: 3, override: undefined, merged: 3, overrides: [{ identifiers: ['x', 'y'], value: 4 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('b', 'y'), { value: 3, override: 4, merged: 4, overrides: [{ identifiers: ['x', 'y'], value: 4 }] });
|
||||
assert.deepStrictEqual(testObject.inspect('c'), { value: 3, override: undefined, merged: 3, overrides: undefined });
|
||||
});
|
||||
|
||||
test('inspect: return all overrides', () => {
|
||||
const testObject = new ConfigurationModel({ 'a': 1, 'c': 1 }, ['a', 'c'], [
|
||||
{ identifiers: ['x', 'y'], contents: { 'a': 2, 'b': 1 }, keys: ['a', 'b'] },
|
||||
{ identifiers: ['x'], contents: { 'a': 3 }, keys: ['a'] },
|
||||
{ identifiers: ['y'], contents: { 'b': 3 }, keys: ['b'] }
|
||||
]);
|
||||
|
||||
assert.deepStrictEqual(testObject.inspect('a').overrides, [
|
||||
{ identifiers: ['x', 'y'], value: 2 },
|
||||
{ identifiers: ['x'], value: 3 }
|
||||
]);
|
||||
});
|
||||
|
||||
test('inspect when no overrides', () => {
|
||||
const testObject = new ConfigurationModel({ 'a': 1, 'c': 1 }, ['a', 'c']);
|
||||
|
||||
assert.strictEqual(testObject.inspect('a').overrides, undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ConfigurationScope, IConfigurationNode, IConfigurationRegistry, Extensi
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
||||
import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
import { ConfigurationTarget, IConfigurationOverrides, IConfigurationService, IConfigurationValue } from 'vs/platform/configuration/common/configuration';
|
||||
import { ConfigurationTarget, IConfigurationService, IConfigurationValue, IInspectValue } from 'vs/platform/configuration/common/configuration';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
|
||||
@@ -117,24 +117,27 @@ export class ConfigurationMigrationWorkbenchContribution extends Disposable impl
|
||||
['workspace', ConfigurationTarget.WORKSPACE],
|
||||
];
|
||||
for (const [dataKey, target] of targetPairs) {
|
||||
const inspectValue = inspectData[dataKey] as IInspectValue<any> | undefined;
|
||||
if (!inspectValue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const migrationValues: [[string, ConfigurationValue], string[]][] = [];
|
||||
|
||||
// Collect migrations for language overrides
|
||||
for (const overrideIdentifier of inspectData.overrideIdentifiers ?? []) {
|
||||
const keyValuePairs = await this.runMigration(migration, { resource, overrideIdentifier }, dataKey);
|
||||
if (inspectValue.value !== undefined) {
|
||||
const keyValuePairs = await this.runMigration(migration, dataKey, inspectValue.value, resource, undefined);
|
||||
for (const keyValuePair of keyValuePairs ?? []) {
|
||||
let keyValueAndOverridesPair = migrationValues.find(([[k, v]]) => k === keyValuePair[0] && equals(v.value, keyValuePair[1].value));
|
||||
if (!keyValueAndOverridesPair) {
|
||||
migrationValues.push(keyValueAndOverridesPair = [keyValuePair, []]);
|
||||
}
|
||||
keyValueAndOverridesPair[1].push(overrideIdentifier);
|
||||
migrationValues.push([keyValuePair, []]);
|
||||
}
|
||||
}
|
||||
|
||||
// Collect migrations
|
||||
const keyValuePairs = await this.runMigration(migration, { resource }, dataKey, inspectData);
|
||||
for (const keyValuePair of keyValuePairs ?? []) {
|
||||
migrationValues.push([keyValuePair, []]);
|
||||
for (const { identifiers, value } of inspectValue.overrides ?? []) {
|
||||
if (value !== undefined) {
|
||||
const keyValuePairs = await this.runMigration(migration, dataKey, value, resource, identifiers);
|
||||
for (const keyValuePair of keyValuePairs ?? []) {
|
||||
migrationValues.push([keyValuePair, identifiers]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (migrationValues.length) {
|
||||
@@ -145,16 +148,18 @@ export class ConfigurationMigrationWorkbenchContribution extends Disposable impl
|
||||
}
|
||||
}
|
||||
|
||||
private async runMigration(migration: ConfigurationMigration, overrides: IConfigurationOverrides, dataKey: keyof IConfigurationValue<any>, data?: IConfigurationValue<any>): Promise<ConfigurationKeyValuePairs | undefined> {
|
||||
const valueAccessor = (key: string) => getInspectValue(this.configurationService.inspect(key, overrides));
|
||||
const getInspectValue = (data: IConfigurationValue<any>) => {
|
||||
const inspectValue: { value?: any; override?: any } | undefined = data[dataKey];
|
||||
return overrides.overrideIdentifier ? inspectValue?.override : inspectValue?.value;
|
||||
private async runMigration(migration: ConfigurationMigration, dataKey: keyof IConfigurationValue<any>, value: any, resource: URI | undefined, overrideIdentifiers: string[] | undefined): Promise<ConfigurationKeyValuePairs | undefined> {
|
||||
const valueAccessor = (key: string) => {
|
||||
const inspectData = this.configurationService.inspect(key, { resource });
|
||||
const inspectValue = inspectData[dataKey] as IInspectValue<any> | undefined;
|
||||
if (!inspectValue) {
|
||||
return undefined;
|
||||
}
|
||||
if (!overrideIdentifiers) {
|
||||
return inspectValue.value;
|
||||
}
|
||||
return inspectValue.overrides?.find(({ identifiers }) => equals(identifiers, overrideIdentifiers))?.value;
|
||||
};
|
||||
const value = data ? getInspectValue(data) : valueAccessor(migration.key);
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const result = await migration.migrateFn(value, valueAccessor);
|
||||
return Array.isArray(result) ? result : [[migration.key, result]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user