From 838dc8f8ae11dce3a905ca592f6c4d1bc9a88ed0 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 10:54:58 +0200 Subject: [PATCH 01/15] register theme service --- src/vs/platform/theme/common/colorUtils.ts | 18 ++++++++++++++++-- .../themes/browser/workbenchThemeService.ts | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 2388e7cb7024c..18617ce424911 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -8,9 +8,12 @@ import { RunOnceScheduler } from 'vs/base/common/async'; import { Color } from 'vs/base/common/color'; import { Emitter, Event } from 'vs/base/common/event'; import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema'; +import { Disposable } from 'vs/base/common/lifecycle.js'; import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; import * as platform from 'vs/platform/registry/common/platform'; import { IColorTheme } from 'vs/platform/theme/common/themeService'; +import { IThemeMainService } from 'vs/platform/theme/electron-main/themeMainService.js'; +import { IHostService } from 'vs/workbench/services/host/browser/host.js'; // ------ API types @@ -128,14 +131,21 @@ class ColorRegistry implements IColorRegistry { private colorSchema: IJSONSchema & { properties: IJSONSchemaMap } = { type: 'object', properties: {} }; private colorReferenceSchema: IJSONSchema & { enum: string[]; enumDescriptions: string[] } = { type: 'string', enum: [], enumDescriptions: [] }; - constructor() { + constructor( + ) { this.colorsById = {}; } + public setThemeService(themeMainService: IThemeMainService) { + themeMainService.onDidChangeColorScheme(x => { + console.log('color theme change') + }) + } + public registerColor(id: string, defaults: ColorDefaults | null, description: string, needsTransparency = false, deprecationMessage?: string): ColorIdentifier { const colorContribution: ColorContribution = { id, description, defaults, needsTransparency, deprecationMessage }; this.colorsById[id] = colorContribution; - const propertySchema: IJSONSchema = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: '${1:#ff0000}' }] }; + const propertySchema: IJSONSchema = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: `\${1:${id}}` }] }; if (deprecationMessage) { propertySchema.deprecationMessage = deprecationMessage; } @@ -211,6 +221,10 @@ export function getColorRegistry(): IColorRegistry { return colorRegistry; } +export const setTheme = (theme: any) => { + colorRegistry.setThemeService(theme) +} + // ----- color functions export function executeTransform(transform: ColorTransform, theme: IColorTheme): Color | undefined { diff --git a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts index e31472e7dade3..5bad2b84c1891 100644 --- a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts +++ b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts @@ -39,7 +39,7 @@ import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hos import { RunOnceScheduler, Sequencer } from 'vs/base/common/async'; import { IUserDataInitializationService } from 'vs/workbench/services/userData/browser/userDataInit'; import { getIconsStyleSheet } from 'vs/platform/theme/browser/iconsStyleSheet'; -import { asCssVariableName, getColorRegistry } from 'vs/platform/theme/common/colorRegistry'; +import { asCssVariableName, getColorRegistry, setTheme } from 'vs/platform/theme/common/colorRegistry'; import { ILanguageService } from 'vs/editor/common/languages/language'; import { mainWindow } from 'vs/base/browser/window'; From 7f950f2205c19235b1c4939f9a42ad87467a8573 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 10:58:36 +0200 Subject: [PATCH 02/15] set color theme --- src/vs/platform/theme/common/colorUtils.ts | 14 +++++--------- .../themes/browser/workbenchThemeService.ts | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 18617ce424911..9f2a826fa85b6 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -8,12 +8,10 @@ import { RunOnceScheduler } from 'vs/base/common/async'; import { Color } from 'vs/base/common/color'; import { Emitter, Event } from 'vs/base/common/event'; import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema'; -import { Disposable } from 'vs/base/common/lifecycle.js'; import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; import * as platform from 'vs/platform/registry/common/platform'; import { IColorTheme } from 'vs/platform/theme/common/themeService'; -import { IThemeMainService } from 'vs/platform/theme/electron-main/themeMainService.js'; -import { IHostService } from 'vs/workbench/services/host/browser/host.js'; +import { ColorThemeData } from 'vs/workbench/services/themes/common/colorThemeData'; // ------ API types @@ -136,10 +134,8 @@ class ColorRegistry implements IColorRegistry { this.colorsById = {}; } - public setThemeService(themeMainService: IThemeMainService) { - themeMainService.onDidChangeColorScheme(x => { - console.log('color theme change') - }) + public setTheme(colorThemeData: ColorThemeData) { + console.log({ colorThemeData }) } public registerColor(id: string, defaults: ColorDefaults | null, description: string, needsTransparency = false, deprecationMessage?: string): ColorIdentifier { @@ -221,8 +217,8 @@ export function getColorRegistry(): IColorRegistry { return colorRegistry; } -export const setTheme = (theme: any) => { - colorRegistry.setThemeService(theme) +export const setTheme = (theme: ColorThemeData) => { + colorRegistry.setTheme(theme) } // ----- color functions diff --git a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts index 5bad2b84c1891..2417578dc8752 100644 --- a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts +++ b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts @@ -486,6 +486,7 @@ export class WorkbenchThemeService extends Disposable implements IWorkbenchTheme } private applyTheme(newTheme: ColorThemeData, settingsTarget: ThemeSettingTarget, silent = false): Promise { + setTheme(newTheme) this.updateDynamicCSSRules(newTheme); if (this.currentColorTheme.id) { From 250e4e3467b12ac83d8da69b4904be0e8b9c5660 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 11:03:27 +0200 Subject: [PATCH 03/15] set default snippet --- src/vs/platform/theme/common/colorUtils.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 9f2a826fa85b6..888fbff4f5c46 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -136,6 +136,17 @@ class ColorRegistry implements IColorRegistry { public setTheme(colorThemeData: ColorThemeData) { console.log({ colorThemeData }) + for (const key of Object.keys(this.colorsById)) { + const color = colorThemeData.getColor(key) + if (!color) { + continue + } + const colorString = color.toString() + this.colorSchema.properties[key].defaultSnippets = [ + { body: `\${1:${colorString}}` } + ] + console.log({ color }) + } } public registerColor(id: string, defaults: ColorDefaults | null, description: string, needsTransparency = false, deprecationMessage?: string): ColorIdentifier { From a1d7e3eb8a28525c08add762340076cfebdcc391 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 11:05:01 +0200 Subject: [PATCH 04/15] remove log --- src/vs/platform/theme/common/colorUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 888fbff4f5c46..7a6a2aa901b9e 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -145,7 +145,6 @@ class ColorRegistry implements IColorRegistry { this.colorSchema.properties[key].defaultSnippets = [ { body: `\${1:${colorString}}` } ] - console.log({ color }) } } From 7d024925e55b345966467e68cf007c7195282607 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 11:05:54 +0200 Subject: [PATCH 05/15] use type import --- src/vs/platform/theme/common/colorUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 7a6a2aa901b9e..1243b54609163 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -11,7 +11,7 @@ import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema'; import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; import * as platform from 'vs/platform/registry/common/platform'; import { IColorTheme } from 'vs/platform/theme/common/themeService'; -import { ColorThemeData } from 'vs/workbench/services/themes/common/colorThemeData'; +import type { ColorThemeData } from 'vs/workbench/services/themes/common/colorThemeData'; // ------ API types From c58e6d7e44edaa89553e9347fb7e9910d1663ffa Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 11:06:09 +0200 Subject: [PATCH 06/15] fix formatting --- src/vs/platform/theme/common/colorUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 1243b54609163..0f18eb5a85a7c 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -129,8 +129,7 @@ class ColorRegistry implements IColorRegistry { private colorSchema: IJSONSchema & { properties: IJSONSchemaMap } = { type: 'object', properties: {} }; private colorReferenceSchema: IJSONSchema & { enum: string[]; enumDescriptions: string[] } = { type: 'string', enum: [], enumDescriptions: [] }; - constructor( - ) { + constructor() { this.colorsById = {}; } From 1cc74812a39be6777e2c8246213050031f53829d Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 11:06:30 +0200 Subject: [PATCH 07/15] undo change --- src/vs/platform/theme/common/colorUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 0f18eb5a85a7c..9024a25703dbc 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -150,8 +150,7 @@ class ColorRegistry implements IColorRegistry { public registerColor(id: string, defaults: ColorDefaults | null, description: string, needsTransparency = false, deprecationMessage?: string): ColorIdentifier { const colorContribution: ColorContribution = { id, description, defaults, needsTransparency, deprecationMessage }; this.colorsById[id] = colorContribution; - const propertySchema: IJSONSchema = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: `\${1:${id}}` }] }; - if (deprecationMessage) { + const propertySchema: IJSONSchema = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: '${1:#ff0000}' }] }; if (deprecationMessage) { propertySchema.deprecationMessage = deprecationMessage; } if (needsTransparency) { From 39940fdef492d6087722f2261f8a60c324cd572b Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 11:08:27 +0200 Subject: [PATCH 08/15] remove log --- src/vs/platform/theme/common/colorUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 9024a25703dbc..478f8abb513ca 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -134,7 +134,6 @@ class ColorRegistry implements IColorRegistry { } public setTheme(colorThemeData: ColorThemeData) { - console.log({ colorThemeData }) for (const key of Object.keys(this.colorsById)) { const color = colorThemeData.getColor(key) if (!color) { From b842b2dba6c9cc258711111c7ee59a3eee8a96be Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 25 May 2024 11:12:54 +0200 Subject: [PATCH 09/15] fix formatting --- src/vs/platform/theme/common/colorUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 478f8abb513ca..0ee87301ab821 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -149,7 +149,8 @@ class ColorRegistry implements IColorRegistry { public registerColor(id: string, defaults: ColorDefaults | null, description: string, needsTransparency = false, deprecationMessage?: string): ColorIdentifier { const colorContribution: ColorContribution = { id, description, defaults, needsTransparency, deprecationMessage }; this.colorsById[id] = colorContribution; - const propertySchema: IJSONSchema = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: '${1:#ff0000}' }] }; if (deprecationMessage) { + const propertySchema: IJSONSchema = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: '${1:#ff0000}' }] }; + if (deprecationMessage) { propertySchema.deprecationMessage = deprecationMessage; } if (needsTransparency) { From 7efdfa4c9375f791e61c09eb966ef446bb9603b2 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Mon, 27 May 2024 19:04:04 +0200 Subject: [PATCH 10/15] rename interface --- src/vs/platform/theme/common/colorUtils.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 0ee87301ab821..3513ff255f84a 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -11,7 +11,6 @@ import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema'; import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; import * as platform from 'vs/platform/registry/common/platform'; import { IColorTheme } from 'vs/platform/theme/common/themeService'; -import type { ColorThemeData } from 'vs/workbench/services/themes/common/colorThemeData'; // ------ API types @@ -133,7 +132,7 @@ class ColorRegistry implements IColorRegistry { this.colorsById = {}; } - public setTheme(colorThemeData: ColorThemeData) { + public setTheme(colorThemeData: IColorTheme) { for (const key of Object.keys(this.colorsById)) { const color = colorThemeData.getColor(key) if (!color) { @@ -225,7 +224,7 @@ export function getColorRegistry(): IColorRegistry { return colorRegistry; } -export const setTheme = (theme: ColorThemeData) => { +export const setTheme = (theme: IColorTheme) => { colorRegistry.setTheme(theme) } From 1d8b43d4c5544cae5eda3b9c85310f0de8261e63 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Mon, 27 May 2024 19:06:17 +0200 Subject: [PATCH 11/15] rename function --- src/vs/platform/theme/common/colorUtils.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 3513ff255f84a..82c310679af81 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -117,6 +117,11 @@ export interface IColorRegistry { */ getColorReferenceSchema(): IJSONSchema; + /** + * Notify when the color theme or settings change. + */ + notifyThemeUpdate(theme: IColorTheme): void + } class ColorRegistry implements IColorRegistry { @@ -132,7 +137,7 @@ class ColorRegistry implements IColorRegistry { this.colorsById = {}; } - public setTheme(colorThemeData: IColorTheme) { + public notifyThemeUpdate(colorThemeData: IColorTheme) { for (const key of Object.keys(this.colorsById)) { const color = colorThemeData.getColor(key) if (!color) { @@ -224,10 +229,6 @@ export function getColorRegistry(): IColorRegistry { return colorRegistry; } -export const setTheme = (theme: IColorTheme) => { - colorRegistry.setTheme(theme) -} - // ----- color functions export function executeTransform(transform: ColorTransform, theme: IColorTheme): Color | undefined { From db49f6b42d711ae1ad682b3dfee2c288e131ad2b Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Mon, 27 May 2024 19:12:26 +0200 Subject: [PATCH 12/15] update listener --- .../services/themes/browser/workbenchThemeService.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts index 2417578dc8752..8fea67043e95d 100644 --- a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts +++ b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts @@ -39,7 +39,7 @@ import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hos import { RunOnceScheduler, Sequencer } from 'vs/base/common/async'; import { IUserDataInitializationService } from 'vs/workbench/services/userData/browser/userDataInit'; import { getIconsStyleSheet } from 'vs/platform/theme/browser/iconsStyleSheet'; -import { asCssVariableName, getColorRegistry, setTheme } from 'vs/platform/theme/common/colorRegistry'; +import { asCssVariableName, getColorRegistry } from 'vs/platform/theme/common/colorRegistry'; import { ILanguageService } from 'vs/editor/common/languages/language'; import { mainWindow } from 'vs/base/browser/window'; @@ -136,6 +136,9 @@ export class WorkbenchThemeService extends Disposable implements IWorkbenchTheme this.currentProductIconTheme = ProductIconThemeData.createUnloadedTheme(''); this.productIconThemeSequencer = new Sequencer(); + this.onColorThemeChange.event + this._register(this.onDidColorThemeChange(this.handleColorThemeChange, this)); + // In order to avoid paint flashing for tokens, because // themes are loaded asynchronously, we need to initialize // a color theme document with good defaults until the theme is loaded @@ -245,6 +248,10 @@ export class WorkbenchThemeService extends Disposable implements IWorkbenchTheme return Promise.all([initializeColorTheme(), initializeFileIconTheme(), initializeProductIconTheme()]); } + private handleColorThemeChange(theme: IColorTheme) { + getColorRegistry().notifyThemeUpdate(theme) + } + private installConfigurationListener() { this._register(this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration(ThemeSettings.COLOR_THEME) @@ -486,7 +493,6 @@ export class WorkbenchThemeService extends Disposable implements IWorkbenchTheme } private applyTheme(newTheme: ColorThemeData, settingsTarget: ThemeSettingTarget, silent = false): Promise { - setTheme(newTheme) this.updateDynamicCSSRules(newTheme); if (this.currentColorTheme.id) { From 44651d4c5c04b90f077a73968eace36ce1002a24 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Tue, 28 May 2024 17:14:09 +0200 Subject: [PATCH 13/15] remove unused code --- .../workbench/services/themes/browser/workbenchThemeService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts index 3dfc8dd60081b..b73df1155fdaf 100644 --- a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts +++ b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts @@ -136,7 +136,6 @@ export class WorkbenchThemeService extends Disposable implements IWorkbenchTheme this.currentProductIconTheme = ProductIconThemeData.createUnloadedTheme(''); this.productIconThemeSequencer = new Sequencer(); - this.onColorThemeChange.event this._register(this.onDidColorThemeChange(this.handleColorThemeChange, this)); // In order to avoid paint flashing for tokens, because From 25a071bdfcbdea9929a64ec6f9bfaec6b11b676b Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Tue, 28 May 2024 17:15:06 +0200 Subject: [PATCH 14/15] inline event listener --- .../services/themes/browser/workbenchThemeService.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts index b73df1155fdaf..327b1d9133ad8 100644 --- a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts +++ b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts @@ -136,7 +136,7 @@ export class WorkbenchThemeService extends Disposable implements IWorkbenchTheme this.currentProductIconTheme = ProductIconThemeData.createUnloadedTheme(''); this.productIconThemeSequencer = new Sequencer(); - this._register(this.onDidColorThemeChange(this.handleColorThemeChange, this)); + this._register(this.onDidColorThemeChange(theme => getColorRegistry().notifyThemeUpdate(theme))); // In order to avoid paint flashing for tokens, because // themes are loaded asynchronously, we need to initialize @@ -247,10 +247,6 @@ export class WorkbenchThemeService extends Disposable implements IWorkbenchTheme return Promise.all([initializeColorTheme(), initializeFileIconTheme(), initializeProductIconTheme()]); } - private handleColorThemeChange(theme: IColorTheme) { - getColorRegistry().notifyThemeUpdate(theme) - } - private installConfigurationListener() { this._register(this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration(ThemeSettings.COLOR_THEME) From ddcbbbbf35aea4ace03c41ae11a7d1a91fc83daf Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Wed, 5 Jun 2024 14:56:32 +0200 Subject: [PATCH 15/15] polish --- src/vs/platform/theme/common/colorUtils.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/vs/platform/theme/common/colorUtils.ts b/src/vs/platform/theme/common/colorUtils.ts index 82c310679af81..ec7ac5ebd9288 100644 --- a/src/vs/platform/theme/common/colorUtils.ts +++ b/src/vs/platform/theme/common/colorUtils.ts @@ -7,7 +7,7 @@ import { assertNever } from 'vs/base/common/assert'; import { RunOnceScheduler } from 'vs/base/common/async'; import { Color } from 'vs/base/common/color'; import { Emitter, Event } from 'vs/base/common/event'; -import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema'; +import { IJSONSchema, IJSONSchemaSnippet } from 'vs/base/common/jsonSchema'; import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; import * as platform from 'vs/platform/registry/common/platform'; import { IColorTheme } from 'vs/platform/theme/common/themeService'; @@ -120,17 +120,20 @@ export interface IColorRegistry { /** * Notify when the color theme or settings change. */ - notifyThemeUpdate(theme: IColorTheme): void + notifyThemeUpdate(theme: IColorTheme): void; } +type IJSONSchemaForColors = IJSONSchema & { properties: { [name: string]: IJSONSchemaWithSnippets } }; +type IJSONSchemaWithSnippets = IJSONSchema & { defaultSnippets: IJSONSchemaSnippet[] }; + class ColorRegistry implements IColorRegistry { private readonly _onDidChangeSchema = new Emitter(); readonly onDidChangeSchema: Event = this._onDidChangeSchema.event; private colorsById: { [key: string]: ColorContribution }; - private colorSchema: IJSONSchema & { properties: IJSONSchemaMap } = { type: 'object', properties: {} }; + private colorSchema: IJSONSchemaForColors = { type: 'object', properties: {} }; private colorReferenceSchema: IJSONSchema & { enum: string[]; enumDescriptions: string[] } = { type: 'string', enum: [], enumDescriptions: [] }; constructor() { @@ -139,21 +142,18 @@ class ColorRegistry implements IColorRegistry { public notifyThemeUpdate(colorThemeData: IColorTheme) { for (const key of Object.keys(this.colorsById)) { - const color = colorThemeData.getColor(key) - if (!color) { - continue + const color = colorThemeData.getColor(key); + if (color) { + this.colorSchema.properties[key].defaultSnippets[0].body = `\${1:${color.toString()}}`; } - const colorString = color.toString() - this.colorSchema.properties[key].defaultSnippets = [ - { body: `\${1:${colorString}}` } - ] } + this._onDidChangeSchema.fire(); } public registerColor(id: string, defaults: ColorDefaults | null, description: string, needsTransparency = false, deprecationMessage?: string): ColorIdentifier { const colorContribution: ColorContribution = { id, description, defaults, needsTransparency, deprecationMessage }; this.colorsById[id] = colorContribution; - const propertySchema: IJSONSchema = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: '${1:#ff0000}' }] }; + const propertySchema: IJSONSchemaWithSnippets = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: '${1:#ff0000}' }] }; if (deprecationMessage) { propertySchema.deprecationMessage = deprecationMessage; }