From 2d0a941fe4ae0fc2d5fbeb145b18a4a88907a2da Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Fri, 26 Nov 2021 13:35:01 +0100 Subject: [PATCH] #134684 override default values from workbenchAssignmentsService for experimental settings --- .../common/configurationRegistry.ts | 11 +++++ .../browser/configurationService.ts | 41 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/vs/platform/configuration/common/configurationRegistry.ts b/src/vs/platform/configuration/common/configurationRegistry.ts index bd3b22eca92bc..d8bc19618b864 100644 --- a/src/vs/platform/configuration/common/configurationRegistry.ts +++ b/src/vs/platform/configuration/common/configurationRegistry.ts @@ -136,8 +136,16 @@ export interface IConfigurationPropertySchema extends IJSONSchema { */ restricted?: boolean; + /** + * When `false` this property is excluded from the registry. Default is to include. + */ included?: boolean; + /** + * List of tags associated to the property. + * - A tag can be used for filtering + * - Use `experimental` tag for marking the setting as experimental. **Note:** Defaults of experimental settings can be changed by the running experiments. + */ tags?: string[]; /** @@ -150,6 +158,9 @@ export interface IConfigurationPropertySchema extends IJSONSchema { */ disallowSyncIgnore?: boolean; + /** + * Labels for enumeration items + */ enumItemLabels?: string[]; /** diff --git a/src/vs/workbench/services/configuration/browser/configurationService.ts b/src/vs/workbench/services/configuration/browser/configurationService.ts index 04dab49ec07c3..083809def009c 100644 --- a/src/vs/workbench/services/configuration/browser/configurationService.ts +++ b/src/vs/workbench/services/configuration/browser/configurationService.ts @@ -36,6 +36,8 @@ import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/w import { delta, distinct } from 'vs/base/common/arrays'; import { forEach, IStringDictionary } from 'vs/base/common/collections'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; +import { IWorkbenchAssignmentService } from 'vs/workbench/services/assignment/common/assignmentService'; +import { isUndefined } from 'vs/base/common/types'; class Workspace extends BaseWorkspace { initialized: boolean = false; @@ -1116,6 +1118,45 @@ class ResetConfigurationDefaultsOverridesCache extends Disposable implements IWo } } +class UpdateExperimentalSettingsDefaults extends Disposable implements IWorkbenchContribution { + + private readonly processedExperimentalSettings = new Set(); + private readonly configurationRegistry = Registry.as(Extensions.Configuration); + + constructor( + @IWorkbenchAssignmentService private readonly workbenchAssignmentService: IWorkbenchAssignmentService + ) { + super(); + this.processExperimentalSettings(Object.keys(this.configurationRegistry.getConfigurationProperties())); + this._register(this.configurationRegistry.onDidUpdateConfiguration(({ properties }) => this.processExperimentalSettings(properties))); + } + + private async processExperimentalSettings(properties: string[]): Promise { + const overrides: IStringDictionary = {}; + const allProperties = this.configurationRegistry.getConfigurationProperties(); + for (const property of properties) { + const schema = allProperties[property]; + if (!schema.tags?.includes('experimental')) { + continue; + } + if (this.processedExperimentalSettings.has(property)) { + continue; + } + this.processedExperimentalSettings.add(property); + try { + const value = await this.workbenchAssignmentService.getTreatment(`config.${property}`); + if (!isUndefined(value) && !equals(value, schema.default)) { + overrides[property] = value; + } + } catch (error) {/*ignore */ } + } + if (Object.keys(overrides).length) { + this.configurationRegistry.registerDefaultConfigurations([{ overrides }]); + } + } +} + const workbenchContributionsRegistry = Registry.as(WorkbenchExtensions.Workbench); workbenchContributionsRegistry.registerWorkbenchContribution(RegisterConfigurationSchemasContribution, LifecyclePhase.Restored); workbenchContributionsRegistry.registerWorkbenchContribution(ResetConfigurationDefaultsOverridesCache, LifecyclePhase.Ready); +workbenchContributionsRegistry.registerWorkbenchContribution(UpdateExperimentalSettingsDefaults, LifecyclePhase.Restored);