From e8184ed571509b6bc1f7752ff2216116f6194ff3 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 9 Jan 2025 17:58:03 +0100 Subject: [PATCH] real fix for #236429 (#237479) --- .../common/configurationModels.ts | 14 +++++--- .../test/browser/configurationService.test.ts | 35 ++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/vs/platform/configuration/common/configurationModels.ts b/src/vs/platform/configuration/common/configurationModels.ts index 400ae1033cb92..468614153ed5b 100644 --- a/src/vs/platform/configuration/common/configurationModels.ts +++ b/src/vs/platform/configuration/common/configurationModels.ts @@ -727,7 +727,7 @@ export class Configuration { } getValue(section: string | undefined, overrides: IConfigurationOverrides, workspace: Workspace | undefined): any { - const consolidateConfigurationModel = this.getConsolidatedConfigurationModel(section, overrides, workspace); + const consolidateConfigurationModel = this.getConsolidatedConfigurationModel(overrides, workspace); return consolidateConfigurationModel.getValue(section); } @@ -755,7 +755,7 @@ export class Configuration { } inspect(key: string, overrides: IConfigurationOverrides, workspace: Workspace | undefined): IConfigurationValue { - const consolidateConfigurationModel = this.getConsolidatedConfigurationModel(key, overrides, workspace); + const consolidateConfigurationModel = this.getConsolidatedConfigurationModel(overrides, workspace); const folderConfigurationModel = this.getFolderConfigurationModelForResource(overrides.resource, workspace); const memoryConfigurationModel = overrides.resource ? this._memoryConfigurationByResource.get(overrides.resource) || this._memoryConfiguration : this._memoryConfiguration; const overrideIdentifiers = new Set(); @@ -965,13 +965,17 @@ export class Configuration { return this._folderConfigurations; } - private getConsolidatedConfigurationModel(section: string | undefined, overrides: IConfigurationOverrides, workspace: Workspace | undefined): ConfigurationModel { + private getConsolidatedConfigurationModel(overrides: IConfigurationOverrides, workspace: Workspace | undefined): ConfigurationModel { let configurationModel = this.getConsolidatedConfigurationModelForResource(overrides, workspace); if (overrides.overrideIdentifier) { configurationModel = configurationModel.override(overrides.overrideIdentifier); } - if (!this._policyConfiguration.isEmpty() && this._policyConfiguration.getValue(section) !== undefined) { - configurationModel = configurationModel.merge(this._policyConfiguration); + if (!this._policyConfiguration.isEmpty()) { + // clone by merging + configurationModel = configurationModel.merge(); + for (const key of this._policyConfiguration.keys) { + configurationModel.setValue(key, this._policyConfiguration.getValue(key)); + } } return configurationModel; } diff --git a/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts b/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts index 833dec287e066..eacc1bacd4a43 100644 --- a/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts +++ b/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts @@ -779,6 +779,14 @@ suite('WorkspaceConfigurationService - Folder', () => { minimumVersion: '1.0.0', } }, + 'configurationService.folder.policyObjectSetting': { + 'type': 'object', + 'default': {}, + policy: { + name: 'configurationService.folder.policyObjectSetting', + minimumVersion: '1.0.0', + } + }, } }); @@ -827,7 +835,19 @@ suite('WorkspaceConfigurationService - Folder', () => { }); test('defaults', () => { - assert.deepStrictEqual(testObject.getValue('configurationService'), { 'folder': { 'applicationSetting': 'isSet', 'machineSetting': 'isSet', 'machineOverridableSetting': 'isSet', 'testSetting': 'isSet', 'languageSetting': 'isSet', 'restrictedSetting': 'isSet', 'policySetting': 'isSet' } }); + assert.deepStrictEqual(testObject.getValue('configurationService'), + { + 'folder': { + 'applicationSetting': 'isSet', + 'machineSetting': 'isSet', + 'machineOverridableSetting': 'isSet', + 'testSetting': 'isSet', + 'languageSetting': 'isSet', + 'restrictedSetting': 'isSet', + 'policySetting': 'isSet', + 'policyObjectSetting': {} + } + }); }); test('globals override defaults', () => runWithFakedTimers({ useFakeTimers: true }, async () => { @@ -1052,6 +1072,19 @@ suite('WorkspaceConfigurationService - Folder', () => { assert.strictEqual(testObject.inspect('configurationService.folder.policySetting').policyValue, undefined); })); + test('policy value override all for object type setting', () => runWithFakedTimers({ useFakeTimers: true }, async () => { + await runWithFakedTimers({ useFakeTimers: true }, async () => { + const promise = Event.toPromise(testObject.onDidChangeConfiguration); + await fileService.writeFile(environmentService.policyFile!, VSBuffer.fromString('{ "configurationService.folder.policyObjectSetting": {"a": true} }')); + return promise; + }); + + await fileService.writeFile(userDataProfileService.currentProfile.settingsResource, VSBuffer.fromString('{ "configurationService.folder.policyObjectSetting": {"b": true} }')); + await testObject.reloadConfiguration(); + + assert.deepStrictEqual(testObject.getValue('configurationService.folder.policyObjectSetting'), { a: true }); + })); + test('reload configuration emits events after global configuraiton changes', () => runWithFakedTimers({ useFakeTimers: true }, async () => { await fileService.writeFile(userDataProfileService.currentProfile.settingsResource, VSBuffer.fromString('{ "testworkbench.editor.tabs": true }')); const target = sinon.spy();