Skip to content

Commit

Permalink
Fix default override model value (#150232)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhao271 authored May 24, 2022
1 parent 54cf6a1 commit ac0a282
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class SettingsTreeIndicatorsLabel {

updateDefaultOverrideIndicator(element: SettingsTreeSettingElement) {
this.defaultOverrideIndicatorElement.style.display = 'none';
const defaultValueSource = element.setting.defaultValueSource;
const defaultValueSource = element.defaultValueSource;
if (defaultValueSource) {
this.defaultOverrideIndicatorElement.style.display = 'inline';
if (typeof defaultValueSource !== 'string' && defaultValueSource.id !== element.setting.extensionInfo?.id) {
Expand Down Expand Up @@ -157,8 +157,8 @@ export function getIndicatorsLabelAriaLabel(element: SettingsTreeSettingElement,
}

// Add default override indicator text
if (element.setting.defaultValueSource) {
const defaultValueSource = element.setting.defaultValueSource;
if (element.defaultValueSource) {
const defaultValueSource = element.defaultValueSource;
if (typeof defaultValueSource !== 'string' && defaultValueSource.id !== element.setting.extensionInfo?.id) {
const extensionSource = defaultValueSource.displayName ?? defaultValueSource.id;
ariaLabelSections.push(localize('defaultOverriddenDetails', "Default setting value overridden by {0}", extensionSource));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ export class SettingComplexRenderer extends AbstractSettingRenderer implements I

template.elementDisposables.add(template.button.onDidClick(() => {
if (isLanguageTagSetting) {
this._onApplyFilter.fire(`@${LANGUAGE_SETTING_TAG}:${plainKey}`);
this._onApplyFilter.fire(`@${LANGUAGE_SETTING_TAG}${plainKey}`);
} else {
this._onDidOpenSettings.fire(dataElement.setting.key);
}
Expand Down
19 changes: 17 additions & 2 deletions src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FOLDER_SCOPES, WORKSPACE_SCOPES, REMOTE_MACHINE_SCOPES, LOCAL_MACHINE_S
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { Disposable } from 'vs/base/common/lifecycle';
import { Emitter } from 'vs/base/common/event';
import { ConfigurationScope, EditPresentationTypes, Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { ConfigurationScope, EditPresentationTypes, Extensions, IConfigurationRegistry, IExtensionInfo } from 'vs/platform/configuration/common/configurationRegistry';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { Registry } from 'vs/platform/registry/common/platform';

Expand Down Expand Up @@ -129,6 +129,12 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {
*/
defaultValue?: any;

/**
* The source of the default value to display.
* This value also accounts for extension-contributed language-specific default value overrides.
*/
defaultValueSource: string | IExtensionInfo | undefined;

/**
* Whether the setting is configured in the selected scope.
*/
Expand All @@ -146,7 +152,12 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {

tags?: Set<string>;
overriddenScopeList: string[] = [];

/**
* For each language that contributes setting values or default overrides, we can see those values here.
*/
languageOverrideValues: Map<string, IConfigurationValue<unknown>> = new Map<string, IConfigurationValue<unknown>>();

description!: string;
valueType!: SettingValueType;

Expand Down Expand Up @@ -219,6 +230,10 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {
}
}

// The user might have added, removed, or modified a language filter,
// so we reset the default value source to the non-language-specific default value source for now.
this.defaultValueSource = this.setting.nonLanguageSpecificDefaultValueSource;

if (inspected.policyValue) {
this.hasPolicyValue = true;
isConfigured = false; // The user did not manually configure the setting themselves.
Expand All @@ -236,7 +251,7 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {
const registryValues = Registry.as<IConfigurationRegistry>(Extensions.Configuration).getConfigurationDefaultsOverrides();
const overrideValueSource = registryValues.get(`[${languageSelector}]`)?.valuesSources?.get(this.setting.key);
if (overrideValueSource) {
this.setting.defaultValueSource = overrideValueSource;
this.defaultValueSource = overrideValueSource;
}
} else {
this.scopeValue = isConfigured && inspected[targetSelector];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export interface ISetting {
enumItemLabels?: string[];
allKeysAreBoolean?: boolean;
editPresentation?: EditPresentationTypes;
defaultValueSource?: string | IExtensionInfo;
nonLanguageSpecificDefaultValueSource?: string | IExtensionInfo;
isLanguageTagSetting?: boolean;
categoryOrder?: number;
categoryLabel?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ export class DefaultSettings extends Disposable {
allKeysAreBoolean,
editPresentation: prop.editPresentation,
order: prop.order,
defaultValueSource,
nonLanguageSpecificDefaultValueSource: defaultValueSource,
isLanguageTagSetting,
categoryLabel,
categoryOrder
Expand Down

0 comments on commit ac0a282

Please sign in to comment.