Skip to content

Commit

Permalink
microsoft#134684 override default values from workbenchAssignmentsSer…
Browse files Browse the repository at this point in the history
…vice for experimental settings
  • Loading branch information
sandy081 authored and Geoffrey committed Nov 30, 2021
1 parent 077507d commit 2d0a941
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/vs/platform/configuration/common/configurationRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

/**
Expand All @@ -150,6 +158,9 @@ export interface IConfigurationPropertySchema extends IJSONSchema {
*/
disallowSyncIgnore?: boolean;

/**
* Labels for enumeration items
*/
enumItemLabels?: string[];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

0 comments on commit 2d0a941

Please sign in to comment.