#134684 override default values from workbenchAssignmentsService for experimental settings

This commit is contained in:
Sandeep Somavarapu 2021-11-26 13:35:01 +01:00
parent d673cdb0ec
commit 39c6132b2c
No known key found for this signature in database
GPG key ID: 1FED25EC4646638B
2 changed files with 52 additions and 0 deletions

View file

@ -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[];
/**

View file

@ -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<string>();
private readonly configurationRegistry = Registry.as<IConfigurationRegistry>(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<void> {
const overrides: IStringDictionary<any> = {};
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<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchContributionsRegistry.registerWorkbenchContribution(RegisterConfigurationSchemasContribution, LifecyclePhase.Restored);
workbenchContributionsRegistry.registerWorkbenchContribution(ResetConfigurationDefaultsOverridesCache, LifecyclePhase.Ready);
workbenchContributionsRegistry.registerWorkbenchContribution(UpdateExperimentalSettingsDefaults, LifecyclePhase.Restored);