Skip to content

Commit

Permalink
Add language overrides and language-specific scopes
Browse files Browse the repository at this point in the history
Ref #151787
Fixes #145731
  • Loading branch information
rzhao271 committed Jun 21, 2022
1 parent 1fabb19 commit 02042c6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 33 deletions.
39 changes: 22 additions & 17 deletions src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,15 @@ export class SettingsEditor2 extends EditorPane {
}));
}

private createSettingsTree(container: HTMLElement): void {
private onApplyFilter(filter: string) {
if (this.searchWidget && !this.searchWidget.getValue().includes(filter)) {
// Prepend the filter to the query.
const newQuery = `${filter} ${this.searchWidget.getValue().trimStart()}`;
this.focusSearch(newQuery, false);
}
}

private createSettingsTree(container: HTMLElement): void {
this.settingRenderers = this.instantiationService.createInstance(SettingTreeRenderers);
this._register(this.settingRenderers.onDidChangeSetting(e => this.onDidChangeSetting(e.key, e.value, e.type, e.manualReset)));
this._register(this.settingRenderers.onDidOpenSettings(settingKey => {
Expand All @@ -847,17 +854,6 @@ export class SettingsEditor2 extends EditorPane {
this._currentFocusContext = SettingsFocusContext.SettingControl;
this.settingRowFocused.set(false);
}));
this._register(this.settingRenderers.onDidClickOverrideElement((element: ISettingOverrideClickEvent) => {
if (element.scope.toLowerCase() === 'workspace') {
this.settingsTargetsWidget.updateTarget(ConfigurationTarget.WORKSPACE);
} else if (element.scope.toLowerCase() === 'user') {
this.settingsTargetsWidget.updateTarget(ConfigurationTarget.USER_LOCAL);
} else if (element.scope.toLowerCase() === 'remote') {
this.settingsTargetsWidget.updateTarget(ConfigurationTarget.USER_REMOTE);
}

this.searchWidget.setValue(element.targetKey);
}));
this._register(this.settingRenderers.onDidChangeSettingHeight((params: HeightChangeParams) => {
const { element, height } = params;
try {
Expand All @@ -866,12 +862,21 @@ export class SettingsEditor2 extends EditorPane {
// the element was not found
}
}));
this._register(this.settingRenderers.onApplyFilter((filter: string) => {
if (this.searchWidget && !this.searchWidget.getValue().includes(filter)) {
// Prepend the filter to the query.
const newQuery = `${filter} ${this.searchWidget.getValue().trimStart()}`;
this.focusSearch(newQuery, false);
this._register(this.settingRenderers.onApplyFilter((filter) => this.onApplyFilter(filter)));
this._register(this.settingRenderers.onDidClickOverrideElement((element: ISettingOverrideClickEvent) => {
if (element.scope.startsWith(`@${LANGUAGE_SETTING_TAG}`)) {
this.onApplyFilter(element.scope);
return;
}

if (element.scope.toLowerCase() === 'workspace') {
this.settingsTargetsWidget.updateTarget(ConfigurationTarget.WORKSPACE);
} else if (element.scope.toLowerCase() === 'user') {
this.settingsTargetsWidget.updateTarget(ConfigurationTarget.USER_LOCAL);
} else if (element.scope.toLowerCase() === 'remote') {
this.settingsTargetsWidget.updateTarget(ConfigurationTarget.USER_REMOTE);
}
this.onApplyFilter(`@${ID_SETTING_TAG}${element.targetKey}`);
}));

this.settingsTree = this._register(this.instantiationService.createInstance(SettingsTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
import * as DOM from 'vs/base/browser/dom';
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
import { IHoverDelegate, IHoverDelegateOptions } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';
import { ITooltipMarkdownString, IUpdatableHoverOptions, setupCustomHover } from 'vs/base/browser/ui/iconLabel/iconLabelHover';
import { ICustomHover, ITooltipMarkdownString, IUpdatableHoverOptions, setupCustomHover } from 'vs/base/browser/ui/iconLabel/iconLabelHover';
import { SimpleIconLabel } from 'vs/base/browser/ui/iconLabel/simpleIconLabel';
import { Emitter } from 'vs/base/common/event';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { localize } from 'vs/nls';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { getIgnoredSettings } from 'vs/platform/userDataSync/common/settingsMerge';
import { getDefaultIgnoredSettings, IUserDataSyncEnablementService } from 'vs/platform/userDataSync/common/userDataSync';
import { SettingsTreeSettingElement } from 'vs/workbench/contrib/preferences/browser/settingsTreeModels';
import { LANGUAGE_SETTING_TAG } from 'vs/workbench/contrib/preferences/common/preferences';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';

const $ = DOM.$;
Expand All @@ -39,7 +41,8 @@ export class SettingsTreeIndicatorsLabel {
container: HTMLElement,
@IConfigurationService configurationService: IConfigurationService,
@IHoverService hoverService: IHoverService,
@IUserDataSyncEnablementService private readonly userDataSyncEnablementService: IUserDataSyncEnablementService) {
@IUserDataSyncEnablementService private readonly userDataSyncEnablementService: IUserDataSyncEnablementService,
@ILanguageService private readonly languageService: ILanguageService) {
this.indicatorsContainerElement = DOM.append(container, $('.misc-label'));
this.indicatorsContainerElement.style.display = 'inline';

Expand Down Expand Up @@ -105,6 +108,15 @@ export class SettingsTreeIndicatorsLabel {
this.render();
}

private getScopeDisplayText(scope: string): string {
if (scope.includes(LANGUAGE_SETTING_TAG)) {
const colonIndex = scope.indexOf(':');
const id = scope.substring(colonIndex + 1);
return this.languageService.getLanguageName(id) ?? id;
}
return scope;
}

updateScopeOverrides(element: SettingsTreeSettingElement, elementDisposables: DisposableStore, onDidClickOverrideElement: Emitter<ISettingOverrideClickEvent>) {
this.scopeOverridesElement.innerText = '';
this.scopeOverridesElement.style.display = 'none';
Expand All @@ -118,7 +130,7 @@ export class SettingsTreeIndicatorsLabel {
this.scopeOverridesLabel.text = `${prefaceText}: `;

const firstScope = element.overriddenScopeList[0];
const view = DOM.append(this.scopeOverridesElement, $('a.modified-scope', undefined, firstScope));
const view = DOM.append(this.scopeOverridesElement, $('a.modified-scope', undefined, this.getScopeDisplayText(firstScope)));
elementDisposables.add(
DOM.addStandardDisposableListener(view, DOM.EventType.CLICK, (e: IMouseEvent) => {
onDidClickOverrideElement.fire({
Expand All @@ -142,8 +154,9 @@ export class SettingsTreeIndicatorsLabel {
let contentMarkdownString = prefaceText;
let contentFallback = prefaceText;
for (const scope of element.overriddenScopeList) {
contentMarkdownString += `\n- [${scope}](${scope})`;
contentFallback += `\n• ${scope}`;
const scopeDisplayText = this.getScopeDisplayText(scope);
contentMarkdownString += `\n- [${scopeDisplayText}](${scope})`;
contentFallback += `\n• ${scopeDisplayText}`;
}
const content: ITooltipMarkdownString = {
markdown: {
Expand All @@ -153,15 +166,17 @@ export class SettingsTreeIndicatorsLabel {
},
markdownNotSupportedFallback: contentFallback
};
let hover: ICustomHover | undefined = undefined;
const options: IUpdatableHoverOptions = {
linkHandler: (scope: string) => {
onDidClickOverrideElement.fire({
targetKey: element.setting.key,
scope
});
hover!.dispose();
}
};
setupCustomHover(this.hoverDelegate, this.scopeOverridesElement, content, options);
hover = setupCustomHover(this.hoverDelegate, this.scopeOverridesElement, content, options);
}
}
this.render();
Expand Down
41 changes: 31 additions & 10 deletions src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { localize } from 'vs/nls';
import { ConfigurationTarget, IConfigurationValue } from 'vs/platform/configuration/common/configuration';
import { SettingsTarget } from 'vs/workbench/contrib/preferences/browser/preferencesWidgets';
import { ITOCEntry, knownAcronyms, knownTermMappings, tocData } from 'vs/workbench/contrib/preferences/browser/settingsLayout';
import { ENABLE_LANGUAGE_FILTER, MODIFIED_SETTING_TAG, POLICY_SETTING_TAG, REQUIRE_TRUSTED_WORKSPACE_SETTING_TAG } from 'vs/workbench/contrib/preferences/common/preferences';
import { ENABLE_LANGUAGE_FILTER, LANGUAGE_SETTING_TAG, MODIFIED_SETTING_TAG, POLICY_SETTING_TAG, REQUIRE_TRUSTED_WORKSPACE_SETTING_TAG } from 'vs/workbench/contrib/preferences/common/preferences';
import { IExtensionSetting, ISearchResult, ISetting, SettingValueType } from 'vs/workbench/services/preferences/common/preferences';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { FOLDER_SCOPES, WORKSPACE_SCOPES, REMOTE_MACHINE_SCOPES, LOCAL_MACHINE_SCOPES, IWorkbenchConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
Expand Down Expand Up @@ -197,6 +197,24 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {
this._displayCategory = displayKeyFormat.category;
}

/**
* Determines whether we need to add more items to the overridden scope list.
*/
private checkTargetSelector(overriddenScopeList: string[], targetSelector: string, inspected: IConfigurationValue<unknown>, languageSelector?: string) {
// We might want to eventually append ` [${languageName}]` to the scope string.
// For now, append nothing.
const languageSelectorSuffix = '';
if (targetSelector !== 'workspaceValue' && typeof inspected.workspaceValue !== 'undefined') {
overriddenScopeList.push(localize('workspace', "Workspace") + languageSelectorSuffix);
}
if (targetSelector !== 'userRemoteValue' && typeof inspected.userRemoteValue !== 'undefined') {
overriddenScopeList.push(localize('remote', "Remote") + languageSelectorSuffix);
}
if (targetSelector !== 'userLocalValue' && typeof inspected.userLocalValue !== 'undefined') {
overriddenScopeList.push(localize('user', "User") + languageSelectorSuffix);
}
}

update(inspectResult: IInspectResult, isWorkspaceTrusted: boolean): void {
let { isConfigured, inspected, targetSelector, inspectedLanguageOverrides, languageSelector } = inspectResult;

Expand All @@ -209,22 +227,25 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {

let displayValue = isConfigured ? inspected[targetSelector] : inspected.defaultValue;
const overriddenScopeList: string[] = [];
if (targetSelector !== 'workspaceValue' && typeof inspected.workspaceValue !== 'undefined') {
overriddenScopeList.push(localize('workspace', "Workspace"));
}

if (targetSelector !== 'userRemoteValue' && typeof inspected.userRemoteValue !== 'undefined') {
overriddenScopeList.push(localize('remote', "Remote"));
}

if (targetSelector !== 'userLocalValue' && typeof inspected.userLocalValue !== 'undefined') {
overriddenScopeList.push(localize('user', "User"));
if (!languageSelector) {
this.checkTargetSelector(overriddenScopeList, targetSelector, inspected);
} else {
const inspected = inspectedLanguageOverrides.get(languageSelector);
if (inspected) {
this.checkTargetSelector(overriddenScopeList, targetSelector, inspected, languageSelector);
}
}

if (inspected.overrideIdentifiers) {
for (const overrideIdentifier of inspected.overrideIdentifiers) {
const inspectedOverride = inspectedLanguageOverrides.get(overrideIdentifier);
if (inspectedOverride) {
if (overrideIdentifier !== languageSelector) {
// Only push in the language override if it's not the language
// we're currently filtered to.
overriddenScopeList.push(`@${LANGUAGE_SETTING_TAG}${overrideIdentifier}`);
}
this.languageOverrideValues.set(overrideIdentifier, inspectedOverride);
}
}
Expand Down

0 comments on commit 02042c6

Please sign in to comment.