diff --git a/src/vs/platform/configuration/common/configuration.ts b/src/vs/platform/configuration/common/configuration.ts index ca25bf1cad3..559b3c18b55 100644 --- a/src/vs/platform/configuration/common/configuration.ts +++ b/src/vs/platform/configuration/common/configuration.ts @@ -70,6 +70,12 @@ export interface IConfigurationChangeEvent { affectsConfiguration(configuration: string, overrides?: IConfigurationOverrides): boolean; } +export interface IInspectValue { + readonly value?: T; + readonly override?: T; + readonly overrides?: { readonly identifiers: string[]; readonly value: T }[]; +} + export interface IConfigurationValue { readonly defaultValue?: T; @@ -83,14 +89,14 @@ export interface IConfigurationValue { 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; + readonly application?: IInspectValue; + readonly user?: IInspectValue; + readonly userLocal?: IInspectValue; + readonly userRemote?: IInspectValue; + readonly workspace?: IInspectValue; + readonly workspaceFolder?: IInspectValue; + readonly memory?: IInspectValue; readonly policy?: { value?: T }; readonly overrideIdentifiers?: string[]; diff --git a/src/vs/platform/configuration/common/configurationModels.ts b/src/vs/platform/configuration/common/configurationModels.ts index 09d12675520..db1f4ee7006 100644 --- a/src/vs/platform/configuration/common/configurationModels.ts +++ b/src/vs/platform/configuration/common/configurationModels.ts @@ -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(data: T): T { return Object.isFrozen(data) ? data : objects.deepFreeze(data); } -interface IInspectValue { - value?: V; - override?: V; - merged?: V; -} +type InspectValue = IInspectValue & { merged?: V }; export class ConfigurationModel implements IConfigurationModel { @@ -82,11 +78,29 @@ export class ConfigurationModel implements IConfigurationModel { return section ? getConfigurationValue(this.contents, section) : this.contents; } - inspect(section: string | undefined, overrideIdentifier?: string | null): IInspectValue { - const value = this.rawConfiguration.getValue(section); - const override = overrideIdentifier ? this.rawConfiguration.getOverrideValue(section, overrideIdentifier) : undefined; - const merged = overrideIdentifier ? this.rawConfiguration.override(overrideIdentifier).getValue(section) : value; - return { value, override, merged }; + inspect(section: string | undefined, overrideIdentifier?: string | null): InspectValue { + const that = this; + return { + get value() { + return freeze(that.rawConfiguration.getValue(section)); + }, + get override() { + return overrideIdentifier ? freeze(that.rawConfiguration.getOverrideValue(section, overrideIdentifier)) : undefined; + }, + get merged() { + return freeze(overrideIdentifier ? that.rawConfiguration.override(overrideIdentifier).getValue(section) : that.rawConfiguration.getValue(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(section); + if (value !== undefined) { + overrides.push({ identifiers, value }); + } + } + return overrides.length ? freeze(overrides) : undefined; + } + }; } getOverrideValue(section: string | undefined, overrideIdentifier: string): V | undefined { @@ -504,19 +518,14 @@ class ConfigurationInspectValue implements IConfigurationValue { return freeze(this._value); } - private inspect(model: ConfigurationModel, section: string | undefined, overrideIdentifier?: string | null): IInspectValue { - const inspectValue = model.inspect(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 | undefined | null): IInspectValue | undefined { + return inspectValue?.value !== undefined || inspectValue?.override !== undefined || inspectValue?.overrides !== undefined ? inspectValue : undefined; } - private _defaultInspectValue: IInspectValue | undefined; - private get defaultInspectValue(): IInspectValue { + private _defaultInspectValue: InspectValue | undefined; + private get defaultInspectValue(): InspectValue { if (!this._defaultInspectValue) { - this._defaultInspectValue = this.inspect(this.defaultConfiguration, this.key, this.overrides.overrideIdentifier); + this._defaultInspectValue = this.defaultConfiguration.inspect(this.key, this.overrides.overrideIdentifier); } return this._defaultInspectValue; } @@ -525,14 +534,14 @@ class ConfigurationInspectValue implements IConfigurationValue { 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 | undefined { + return this.toInspectValue(this.defaultInspectValue); } - private _policyInspectValue: IInspectValue | undefined | null; - private get policyInspectValue(): IInspectValue | null { + private _policyInspectValue: InspectValue | undefined | null; + private get policyInspectValue(): InspectValue | null { if (this._policyInspectValue === undefined) { - this._policyInspectValue = this.policyConfiguration ? this.inspect(this.policyConfiguration, this.key) : null; + this._policyInspectValue = this.policyConfiguration ? this.policyConfiguration.inspect(this.key) : null; } return this._policyInspectValue; } @@ -541,14 +550,14 @@ class ConfigurationInspectValue implements IConfigurationValue { return this.policyInspectValue?.merged; } - get policy(): { value?: V; override?: V } | undefined { + get policy(): IInspectValue | undefined { return this.policyInspectValue?.value !== undefined ? { value: this.policyInspectValue.value } : undefined; } - private _applicationInspectValue: IInspectValue | undefined | null; - private get applicationInspectValue(): IInspectValue | null { + private _applicationInspectValue: InspectValue | undefined | null; + private get applicationInspectValue(): InspectValue | null { if (this._applicationInspectValue === undefined) { - this._applicationInspectValue = this.applicationConfiguration ? this.inspect(this.applicationConfiguration, this.key) : null; + this._applicationInspectValue = this.applicationConfiguration ? this.applicationConfiguration.inspect(this.key) : null; } return this._applicationInspectValue; } @@ -557,14 +566,14 @@ class ConfigurationInspectValue implements IConfigurationValue { 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 | undefined { + return this.toInspectValue(this.applicationInspectValue); } - private _userInspectValue: IInspectValue | undefined; - private get userInspectValue(): IInspectValue { + private _userInspectValue: InspectValue | undefined; + private get userInspectValue(): InspectValue { if (!this._userInspectValue) { - this._userInspectValue = this.inspect(this.userConfiguration, this.key, this.overrides.overrideIdentifier); + this._userInspectValue = this.userConfiguration.inspect(this.key, this.overrides.overrideIdentifier); } return this._userInspectValue; } @@ -573,14 +582,14 @@ class ConfigurationInspectValue implements IConfigurationValue { 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 | undefined { + return this.toInspectValue(this.userInspectValue); } - private _userLocalInspectValue: IInspectValue | undefined; - private get userLocalInspectValue(): IInspectValue { + private _userLocalInspectValue: InspectValue | undefined; + private get userLocalInspectValue(): InspectValue { if (!this._userLocalInspectValue) { - this._userLocalInspectValue = this.inspect(this.localUserConfiguration, this.key, this.overrides.overrideIdentifier); + this._userLocalInspectValue = this.localUserConfiguration.inspect(this.key, this.overrides.overrideIdentifier); } return this._userLocalInspectValue; } @@ -589,14 +598,14 @@ class ConfigurationInspectValue implements IConfigurationValue { 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 | undefined { + return this.toInspectValue(this.userLocalInspectValue); } - private _userRemoteInspectValue: IInspectValue | undefined; - private get userRemoteInspectValue(): IInspectValue { + private _userRemoteInspectValue: InspectValue | undefined; + private get userRemoteInspectValue(): InspectValue { if (!this._userRemoteInspectValue) { - this._userRemoteInspectValue = this.inspect(this.remoteUserConfiguration, this.key, this.overrides.overrideIdentifier); + this._userRemoteInspectValue = this.remoteUserConfiguration.inspect(this.key, this.overrides.overrideIdentifier); } return this._userRemoteInspectValue; } @@ -605,14 +614,14 @@ class ConfigurationInspectValue implements IConfigurationValue { 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 | undefined { + return this.toInspectValue(this.userRemoteInspectValue); } - private _workspaceInspectValue: IInspectValue | undefined | null; - private get workspaceInspectValue(): IInspectValue | null { + private _workspaceInspectValue: InspectValue | undefined | null; + private get workspaceInspectValue(): InspectValue | null { if (this._workspaceInspectValue === undefined) { - this._workspaceInspectValue = this.workspaceConfiguration ? this.inspect(this.workspaceConfiguration, this.key, this.overrides.overrideIdentifier) : null; + this._workspaceInspectValue = this.workspaceConfiguration ? this.workspaceConfiguration.inspect(this.key, this.overrides.overrideIdentifier) : null; } return this._workspaceInspectValue; } @@ -621,14 +630,14 @@ class ConfigurationInspectValue implements IConfigurationValue { 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 | undefined { + return this.toInspectValue(this.workspaceInspectValue); } - private _workspaceFolderInspectValue: IInspectValue | undefined | null; - private get workspaceFolderInspectValue(): IInspectValue | null { + private _workspaceFolderInspectValue: InspectValue | undefined | null; + private get workspaceFolderInspectValue(): InspectValue | null { if (this._workspaceFolderInspectValue === undefined) { - this._workspaceFolderInspectValue = this.folderConfigurationModel ? this.inspect(this.folderConfigurationModel, this.key, this.overrides.overrideIdentifier) : null; + this._workspaceFolderInspectValue = this.folderConfigurationModel ? this.folderConfigurationModel.inspect(this.key, this.overrides.overrideIdentifier) : null; } return this._workspaceFolderInspectValue; } @@ -637,14 +646,14 @@ class ConfigurationInspectValue implements IConfigurationValue { 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 | undefined { + return this.toInspectValue(this.workspaceFolderInspectValue); } - private _memoryInspectValue: IInspectValue | undefined; - private get memoryInspectValue(): IInspectValue { + private _memoryInspectValue: InspectValue | undefined; + private get memoryInspectValue(): InspectValue { if (this._memoryInspectValue === undefined) { - this._memoryInspectValue = this.inspect(this.memoryConfigurationModel, this.key, this.overrides.overrideIdentifier); + this._memoryInspectValue = this.memoryConfigurationModel.inspect(this.key, this.overrides.overrideIdentifier); } return this._memoryInspectValue; } @@ -653,8 +662,8 @@ class ConfigurationInspectValue implements IConfigurationValue { 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 | undefined { + return this.toInspectValue(this.memoryInspectValue); } } diff --git a/src/vs/platform/configuration/test/common/configurationModels.test.ts b/src/vs/platform/configuration/test/common/configurationModels.test.ts index c1a5a0623c6..605ae8b6517 100644 --- a/src/vs/platform/configuration/test/common/configurationModels.test.ts +++ b/src/vs/platform/configuration/test/common/configurationModels.test.ts @@ -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); }); }); diff --git a/src/vs/workbench/common/configuration.ts b/src/vs/workbench/common/configuration.ts index d9ebf02b99b..67d90393d59 100644 --- a/src/vs/workbench/common/configuration.ts +++ b/src/vs/workbench/common/configuration.ts @@ -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 | 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, data?: IConfigurationValue): Promise { - const valueAccessor = (key: string) => getInspectValue(this.configurationService.inspect(key, overrides)); - const getInspectValue = (data: IConfigurationValue) => { - const inspectValue: { value?: any; override?: any } | undefined = data[dataKey]; - return overrides.overrideIdentifier ? inspectValue?.override : inspectValue?.value; + private async runMigration(migration: ConfigurationMigration, dataKey: keyof IConfigurationValue, value: any, resource: URI | undefined, overrideIdentifiers: string[] | undefined): Promise { + const valueAccessor = (key: string) => { + const inspectData = this.configurationService.inspect(key, { resource }); + const inspectValue = inspectData[dataKey] as IInspectValue | 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]]; }