Skip to content

Commit 41e9b95

Browse files
committed
product icons: fix schema (fixes microsoft#94215)
1 parent 7456cf8 commit 41e9b95

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

src/vs/platform/theme/common/iconRegistry.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
88
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
99
import { Event, Emitter } from 'vs/base/common/event';
1010
import { localize } from 'vs/nls';
11+
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
12+
import { RunOnceScheduler } from 'vs/base/common/async';
1113

1214
// ------ API types
1315

@@ -18,7 +20,7 @@ export const Extensions = {
1820
};
1921

2022
export interface IconDefaults {
21-
font?: string;
23+
fontId?: string;
2224
character: string;
2325
}
2426

@@ -69,7 +71,21 @@ class IconRegistry implements IIconRegistry {
6971
readonly onDidChangeSchema: Event<void> = this._onDidChangeSchema.event;
7072

7173
private iconsById: { [key: string]: IconContribution };
72-
private iconSchema: IJSONSchema & { properties: IJSONSchemaMap } = { type: 'object', properties: {} };
74+
private iconSchema: IJSONSchema & { properties: IJSONSchemaMap } = {
75+
definitions: {
76+
icons: {
77+
type: 'object',
78+
properties: {
79+
fontId: { type: 'string', description: localize('iconDefintion.fontId', 'The id of the font to use. If not set, the font that is defined first is used.') },
80+
fontCharacter: { type: 'string', description: localize('iconDefintion.fontCharacter', 'The font character associated with the icon definition.') }
81+
},
82+
additionalProperties: false,
83+
defaultSnippets: [{ body: { fontCharacter: '\\\\e030' } }]
84+
}
85+
},
86+
type: 'object',
87+
properties: {}
88+
};
7389
private iconReferenceSchema: IJSONSchema & { enum: string[], enumDescriptions: string[] } = { type: 'string', enum: [], enumDescriptions: [] };
7490

7591
constructor() {
@@ -79,7 +95,7 @@ class IconRegistry implements IIconRegistry {
7995
public registerIcon(id: string, defaults: IconDefaults, description: string, deprecationMessage?: string): ThemeIcon {
8096
let iconContribution: IconContribution = { id, description, defaults, deprecationMessage };
8197
this.iconsById[id] = iconContribution;
82-
let propertySchema: IJSONSchema = { type: 'object', description, properties: { font: { type: 'string' }, fontCharacter: { type: 'string' } }, defaultSnippets: [{ body: { fontCharacter: '\\\\e030' } }] };
98+
let propertySchema: IJSONSchema = { description, $ref: '#/definitions/icons' };
8399
if (deprecationMessage) {
84100
propertySchema.deprecationMessage = deprecationMessage;
85101
}
@@ -539,5 +555,17 @@ registerIcon('bell-dot', { character: '\f101' }, localize('bell-dot', ''));
539555
registerIcon('debug-alt-2', { character: '\f102' }, localize('debug-alt-2', ''));
540556
registerIcon('debug-alt', { character: '\f103' }, localize('debug-alt', ''));
541557

558+
export const iconsSchemaId = 'vscode://schemas/icons';
559+
560+
let schemaRegistry = platform.Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
561+
schemaRegistry.registerSchema(iconsSchemaId, iconRegistry.getIconSchema());
562+
563+
const delayer = new RunOnceScheduler(() => schemaRegistry.notifySchemaChanged(iconsSchemaId), 200);
564+
iconRegistry.onDidChangeSchema(() => {
565+
if (!delayer.isScheduled()) {
566+
delayer.schedule();
567+
}
568+
});
569+
542570

543571
// setTimeout(_ => console.log(colorRegistry.toString()), 5000);

src/vs/workbench/services/themes/common/productIconThemeSchema.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
77
import { Registry } from 'vs/platform/registry/common/platform';
88
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
99
import { IJSONSchema } from 'vs/base/common/jsonSchema';
10-
import { getIconRegistry } from 'vs/platform/theme/common/iconRegistry';
10+
import { iconsSchemaId } from 'vs/platform/theme/common/iconRegistry';
1111

1212

1313
const schemaId = 'vscode://schemas/product-icon-theme';
@@ -67,9 +67,8 @@ const schema: IJSONSchema = {
6767
}
6868
},
6969
iconDefinitions: {
70-
type: 'object',
71-
description: nls.localize('schema.iconDefinitions', 'Assocation of icon name to a font character.'),
72-
properties: getIconRegistry().getIconSchema().properties,
70+
description: nls.localize('schema.iconDefinitions', 'Association of icon name to a font character.'),
71+
$ref: iconsSchemaId,
7372
additionalProperties: false
7473
}
7574
}

0 commit comments

Comments
 (0)