From eda73b0ef730908aace26e5f59350ed47baa6c0e Mon Sep 17 00:00:00 2001 From: Colin Grant Date: Thu, 23 Mar 2023 15:31:42 -0600 Subject: [PATCH 1/2] Use nodes' schemata as source of truth --- packages/preferences/package.json | 1 + .../components/preference-node-renderer.ts | 7 +++++- .../browser/views/preference-editor-widget.ts | 24 ++++--------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/packages/preferences/package.json b/packages/preferences/package.json index 3cfe195bf9bba..bfea605694a7d 100644 --- a/packages/preferences/package.json +++ b/packages/preferences/package.json @@ -11,6 +11,7 @@ "@theia/userstorage": "1.35.0", "@theia/workspace": "1.35.0", "async-mutex": "^0.3.1", + "fast-deep-equal": "^3.1.3", "jsonc-parser": "^2.2.0", "p-debounce": "^2.1.0" }, diff --git a/packages/preferences/src/browser/views/components/preference-node-renderer.ts b/packages/preferences/src/browser/views/components/preference-node-renderer.ts index 74de4499c6225..2b3161df1b08e 100644 --- a/packages/preferences/src/browser/views/components/preference-node-renderer.ts +++ b/packages/preferences/src/browser/views/components/preference-node-renderer.ts @@ -17,7 +17,7 @@ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify'; import { PreferenceService, ContextMenuRenderer, PreferenceInspection, - PreferenceScope, PreferenceProvider, codicon, OpenerService, open + PreferenceScope, PreferenceProvider, codicon, OpenerService, open, PreferenceDataProperty } from '@theia/core/lib/browser'; import { Preference, PreferenceMenus } from '../../util/preference-types'; import { PreferenceTreeLabelProvider } from '../../util/preference-tree-label-provider'; @@ -39,6 +39,7 @@ export const SUBHEADER_CLASS = 'settings-section-subcategory-title'; export interface GeneralPreferenceNodeRenderer extends Disposable { node: HTMLElement; id: string; + schema?: PreferenceDataProperty; group: string; nodeId: string; visible: boolean; @@ -170,6 +171,10 @@ export abstract class PreferenceLeafNodeRenderer Date: Fri, 24 Mar 2023 08:46:06 -0600 Subject: [PATCH 2/2] Use new object to avoid referential equality --- packages/core/src/browser/icon-theme-service.ts | 8 +++++--- .../src/browser/preferences/preference-contribution.ts | 4 ++++ packages/core/src/browser/theming.ts | 8 +++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/core/src/browser/icon-theme-service.ts b/packages/core/src/browser/icon-theme-service.ts index 7808401e209d5..862890df9718e 100644 --- a/packages/core/src/browser/icon-theme-service.ts +++ b/packages/core/src/browser/icon-theme-service.ts @@ -198,9 +198,11 @@ export class IconThemeService { const preference = this.schemaProvider.getSchemaProperty(ICON_THEME_PREFERENCE_KEY); if (preference) { const sortedThemes = Array.from(this.definitions).sort((a, b) => a.label.localeCompare(b.label)); - preference.enum = sortedThemes.map(e => e.id); - preference.enumItemLabels = sortedThemes.map(e => e.label); - this.schemaProvider.updateSchemaProperty(ICON_THEME_PREFERENCE_KEY, preference); + this.schemaProvider.updateSchemaProperty(ICON_THEME_PREFERENCE_KEY, { + ...preference, + enum: sortedThemes.map(e => e.id), + enumItemLabels: sortedThemes.map(e => e.label) + }); } } diff --git a/packages/core/src/browser/preferences/preference-contribution.ts b/packages/core/src/browser/preferences/preference-contribution.ts index 6c58ef88ffb06..b91b71aff265f 100644 --- a/packages/core/src/browser/preferences/preference-contribution.ts +++ b/packages/core/src/browser/preferences/preference-contribution.ts @@ -360,6 +360,10 @@ export class PreferenceSchemaProvider extends PreferenceProvider { return this.combinedSchema.properties[key]; } + /** + * {@link property} will be assigned to field {@link key} in the schema. + * Pass a new object to invalidate old schema. + */ updateSchemaProperty(key: string, property: PreferenceDataProperty): void { this.updateSchemaProps(key, property); this.fireDidPreferenceSchemaChanged(); diff --git a/packages/core/src/browser/theming.ts b/packages/core/src/browser/theming.ts index 2a8e90b0d68db..ddcc47991ee28 100644 --- a/packages/core/src/browser/theming.ts +++ b/packages/core/src/browser/theming.ts @@ -91,9 +91,11 @@ export class ThemeService { const preference = this.schemaProvider.getSchemaProperty(COLOR_THEME_PREFERENCE_KEY); if (preference) { const sortedThemes = this.getThemes().sort((a, b) => a.label.localeCompare(b.label)); - preference.enum = sortedThemes.map(e => e.id); - preference.enumItemLabels = sortedThemes.map(e => e.label); - this.schemaProvider.updateSchemaProperty(COLOR_THEME_PREFERENCE_KEY, preference); + this.schemaProvider.updateSchemaProperty(COLOR_THEME_PREFERENCE_KEY, { + ...preference, + enum: sortedThemes.map(e => e.id), + enumItemLabels: sortedThemes.map(e => e.label) + }); } }