Skip to content

Commit

Permalink
real fix for #236429 (#237479)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored Jan 9, 2025
1 parent da4fcc5 commit e8184ed
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/vs/platform/configuration/common/configurationModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -755,7 +755,7 @@ export class Configuration {
}

inspect<C>(key: string, overrides: IConfigurationOverrides, workspace: Workspace | undefined): IConfigurationValue<C> {
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<string>();
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
},
}
});

Expand Down Expand Up @@ -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<void>({ useFakeTimers: true }, async () => {
Expand Down Expand Up @@ -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<void>({ 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<void>({ useFakeTimers: true }, async () => {
await fileService.writeFile(userDataProfileService.currentProfile.settingsResource, VSBuffer.fromString('{ "testworkbench.editor.tabs": true }'));
const target = sinon.spy();
Expand Down

0 comments on commit e8184ed

Please sign in to comment.