Skip to content

Commit

Permalink
separate schema for workbenchColors and textmateColors, to avoid repe…
Browse files Browse the repository at this point in the history
…tition in configuration schemas
  • Loading branch information
aeschli committed Jan 23, 2019
1 parent 2702ef2 commit 6220dcd
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 95 deletions.
8 changes: 7 additions & 1 deletion src/vs/platform/theme/common/colorRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Color, RGBA } from 'vs/base/common/color';
import { ITheme } from 'vs/platform/theme/common/themeService';

import * as nls from 'vs/nls';
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';

// ------ API types

Expand Down Expand Up @@ -79,7 +80,7 @@ export interface IColorRegistry {

class ColorRegistry implements IColorRegistry {
private colorsById: { [key: string]: ColorContribution };
private colorSchema: IJSONSchema = { type: 'object', description: nls.localize('schema.colors', "Colors used in the workbench."), properties: {}, additionalProperties: false };
private colorSchema: IJSONSchema = { type: 'object', properties: {} };
private colorReferenceSchema: IJSONSchema = { type: 'string', enum: [], enumDescriptions: [] };

constructor() {
Expand Down Expand Up @@ -443,6 +444,11 @@ function resolveColorValue(colorValue: ColorValue | null, theme: ITheme): Color
return null;
}

export const workbenchColorsSchemaId = 'vscode:https://schemas/workbench-colors';

let schemaRegistry = platform.Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
schemaRegistry.registerSchema(workbenchColorsSchemaId, colorRegistry.getColorSchema());

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { Color } from 'vs/base/common/color';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { LIGHT, DARK, HIGH_CONTRAST } from 'vs/platform/theme/common/themeService';
import { schemaId } from 'vs/workbench/services/themes/common/colorThemeSchema';
import { colorThemeSchemaId } from 'vs/workbench/services/themes/common/colorThemeSchema';
import { onUnexpectedError } from 'vs/base/common/errors';
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';

Expand Down Expand Up @@ -216,7 +216,7 @@ class GenerateColorThemeAction extends Action {
}
}
let contents = JSON.stringify({
'$schema': schemaId,
'$schema': colorThemeSchemaId,
type: theme.type,
colors: resultingColors,
tokenColors: theme.tokenColors.filter(t => !!t.scope)
Expand Down
152 changes: 82 additions & 70 deletions src/vs/workbench/services/themes/common/colorThemeSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';

import { Extensions as ThemeingExtensions, IColorRegistry } from 'vs/platform/theme/common/colorRegistry';
import { workbenchColorsSchemaId } from 'vs/platform/theme/common/colorRegistry';

let themingRegistry = Registry.as<IColorRegistry>(ThemeingExtensions.ColorContribution);
let textMateScopes = [
'comment',
'comment.block',
Expand Down Expand Up @@ -114,97 +113,110 @@ let textMateScopes = [
'variable.parameter'
];

export const tokenColorizationSettingSchema: IJSONSchema = {
type: 'object',
description: nls.localize('schema.token.settings', 'Colors and styles for the token.'),
properties: {
foreground: {
type: 'string',
description: nls.localize('schema.token.foreground', 'Foreground color for the token.'),
format: 'color-hex',
default: '#ff0000'
},
background: {
type: 'string',
deprecationMessage: nls.localize('schema.token.background.warning', 'Token background colors are currently not supported.')
},
fontStyle: {
type: 'string',
description: nls.localize('schema.token.fontStyle', 'Font style of the rule: \'italic\', \'bold\' or \'underline\' or a combination. The empty string unsets inherited settings.'),
pattern: '^(\\s*\\b(italic|bold|underline))*\\s*$',
patternErrorMessage: nls.localize('schema.fontStyle.error', 'Font style must be \'italic\', \'bold\' or \'underline\' or a combination or the empty string.'),
defaultSnippets: [{ label: nls.localize('schema.token.fontStyle.none', 'None (clear inherited style)'), bodyText: '""' }, { body: 'italic' }, { body: 'bold' }, { body: 'underline' }, { body: 'italic bold' }, { body: 'italic underline' }, { body: 'bold underline' }, { body: 'italic bold underline' }]
}
},
additionalProperties: false,
defaultSnippets: [{ body: { foreground: '${1:#FF0000}', fontStyle: '${2:bold}' } }]
};
export const textmateColorsSchemaId = 'vscode:https://schemas/textmate-colors';
export const textmateColorSettingsSchemaId = `${textmateColorsSchemaId}#definitions/settings`;

export const colorsSchema = themingRegistry.getColorSchema();
export function tokenColorsSchema(description: string): IJSONSchema {
return {
type: 'array',
description,
items: {
const textmateColorSchema: IJSONSchema = {
type: 'array',
definitions: {
settings: {
type: 'object',
defaultSnippets: [{ body: { scope: '${1:keyword.operator}', settings: { foreground: '${2:#FF0000}' } } }],
description: nls.localize('schema.token.settings', 'Colors and styles for the token.'),
properties: {
name: {
foreground: {
type: 'string',
description: nls.localize('schema.properties.name', 'Description of the rule.')
description: nls.localize('schema.token.foreground', 'Foreground color for the token.'),
format: 'color-hex',
default: '#ff0000'
},
scope: {
description: nls.localize('schema.properties.scope', 'Scope selector against which this rule matches.'),
anyOf: [
{
background: {
type: 'string',
deprecationMessage: nls.localize('schema.token.background.warning', 'Token background colors are currently not supported.')
},
fontStyle: {
type: 'string',
description: nls.localize('schema.token.fontStyle', 'Font style of the rule: \'italic\', \'bold\' or \'underline\' or a combination. The empty string unsets inherited settings.'),
pattern: '^(\\s*\\b(italic|bold|underline))*\\s*$',
patternErrorMessage: nls.localize('schema.fontStyle.error', 'Font style must be \'italic\', \'bold\' or \'underline\' or a combination or the empty string.'),
defaultSnippets: [{ label: nls.localize('schema.token.fontStyle.none', 'None (clear inherited style)'), bodyText: '""' }, { body: 'italic' }, { body: 'bold' }, { body: 'underline' }, { body: 'italic bold' }, { body: 'italic underline' }, { body: 'bold underline' }, { body: 'italic bold underline' }]
}
},
additionalProperties: false,
defaultSnippets: [{ body: { foreground: '${1:#FF0000}', fontStyle: '${2:bold}' } }]
}
},
items: {
type: 'object',
defaultSnippets: [{ body: { scope: '${1:keyword.operator}', settings: { foreground: '${2:#FF0000}' } } }],
properties: {
name: {
type: 'string',
description: nls.localize('schema.properties.name', 'Description of the rule.')
},
scope: {
description: nls.localize('schema.properties.scope', 'Scope selector against which this rule matches.'),
anyOf: [
{
enum: textMateScopes
},
{
type: 'string'
},
{
type: 'array',
items: {
enum: textMateScopes
},
{
}
},
{
type: 'array',
items: {
type: 'string'
},
{
type: 'array',
items: {
enum: textMateScopes
}
},
{
type: 'array',
items: {
type: 'string'
}
}
]
},
settings: tokenColorizationSettingSchema,
}
]
},
required: [
'settings', 'scope'
],
additionalProperties: false
}
};
}
settings: {
$ref: '#definitions/settings'
}
},
required: [
'settings', 'scope'
],
additionalProperties: false
}
};

export const schemaId = 'vscode:https://schemas/color-theme';
const schema: IJSONSchema = {
export const colorThemeSchemaId = 'vscode:https://schemas/color-theme';

const colorThemeSchema: IJSONSchema = {
type: 'object',
allowComments: true,
properties: {
colors: colorsSchema,
colors: {
description: nls.localize('schema.workbenchColors', 'Colors in the workbench'),
$ref: workbenchColorsSchemaId,
additionalProperties: false
},
tokenColors: {
anyOf: [{
type: 'string',
description: nls.localize('schema.tokenColors.path', 'Path to a tmTheme file (relative to the current file).')
},
tokenColorsSchema(nls.localize('schema.colors', 'Colors for syntax highlighting'))
{
description: nls.localize('schema.colors', 'Colors for syntax highlighting'),
$ref: textmateColorsSchemaId
}
]
}
}
};

export function register() {


export function registerColorThemeSchemas() {
let schemaRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
schemaRegistry.registerSchema(schemaId, schema);
schemaRegistry.registerSchema(colorThemeSchemaId, colorThemeSchema);
schemaRegistry.registerSchema(textmateColorsSchemaId, textmateColorSchema);
}

Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const schema: IJSONSchema = {
}
};

export function register() {
export function registerFileIconThemeSchemas() {
let schemaRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
schemaRegistry.registerSchema(schemaId, schema);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const DETECT_HC_SETTING = 'window.autoDetectHighContrast';
export const ICON_THEME_SETTING = 'workbench.iconTheme';
export const CUSTOM_WORKBENCH_COLORS_SETTING = 'workbench.colorCustomizations';
export const CUSTOM_EDITOR_COLORS_SETTING = 'editor.tokenColorCustomizations';
export const CUSTOM_EDITOR_SCOPE_COLORS_SETTING = 'textMateRules';

export interface IColorTheme extends ITheme {
readonly id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as nls from 'vs/nls';
import * as types from 'vs/base/common/types';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IWorkbenchThemeService, IColorTheme, ITokenColorCustomizations, IFileIconTheme, ExtensionData, VS_LIGHT_THEME, VS_DARK_THEME, VS_HC_THEME, COLOR_THEME_SETTING, ICON_THEME_SETTING, CUSTOM_WORKBENCH_COLORS_SETTING, CUSTOM_EDITOR_COLORS_SETTING, CUSTOM_EDITOR_SCOPE_COLORS_SETTING, DETECT_HC_SETTING, HC_THEME_ID } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IWorkbenchThemeService, IColorTheme, ITokenColorCustomizations, IFileIconTheme, ExtensionData, VS_LIGHT_THEME, VS_DARK_THEME, VS_HC_THEME, COLOR_THEME_SETTING, ICON_THEME_SETTING, CUSTOM_WORKBENCH_COLORS_SETTING, CUSTOM_EDITOR_COLORS_SETTING, DETECT_HC_SETTING, HC_THEME_ID } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Registry } from 'vs/platform/registry/common/platform';
Expand All @@ -17,8 +17,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { ColorThemeData } from './colorThemeData';
import { ITheme, Extensions as ThemingExtensions, IThemingRegistry } from 'vs/platform/theme/common/themeService';
import { Event, Emitter } from 'vs/base/common/event';
import * as colorThemeSchema from 'vs/workbench/services/themes/common/colorThemeSchema';
import * as fileIconThemeSchema from 'vs/workbench/services/themes/common/fileIconThemeSchema';
import { registerFileIconThemeSchemas } from 'vs/workbench/services/themes/common/fileIconThemeSchema';
import { IDisposable } from 'vs/base/common/lifecycle';
import { ColorThemeStore } from 'vs/workbench/services/themes/electron-browser/colorThemeStore';
import { FileIconThemeStore } from 'vs/workbench/services/themes/electron-browser/fileIconThemeStore';
Expand All @@ -29,7 +28,9 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IFileService, FileChangeType } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import * as resources from 'vs/base/common/resources';
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { textmateColorsSchemaId, registerColorThemeSchemas, textmateColorSettingsSchemaId } from 'vs/workbench/services/themes/common/colorThemeSchema';
import { workbenchColorsSchemaId } from 'vs/platform/theme/common/colorRegistry';

// implementation

Expand Down Expand Up @@ -149,12 +150,17 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
const themeSpecificWorkbenchColors: IJSONSchema = { properties: {} };
const themeSpecificTokenColors: IJSONSchema = { properties: {} };

const workbenchColors = { $ref: workbenchColorsSchemaId, additionalProperties: false };
const tokenColors = { properties: tokenColorSchema.properties, additionalProperties: false };
for (let t of themes) {
// add a enum value to the 'workbench.colorTheme` setting
colorThemeSettingSchema.enum!.push(t.settingsId);
colorThemeSettingSchema.enumDescriptions!.push(t.description || '');

// add theme specific color customization ("[Abyss]":{ ... })
const themeId = `[${t.settingsId}]`;
themeSpecificWorkbenchColors.properties![themeId] = colorThemeSchema.colorsSchema;
themeSpecificTokenColors.properties![themeId] = { properties: tokenColorConfigurationProperties, additionalProperties: false };
themeSpecificWorkbenchColors.properties![themeId] = workbenchColors;
themeSpecificTokenColors.properties![themeId] = tokenColors;
}

colorCustomizationsSchema.allOf![1] = themeSpecificWorkbenchColors;
Expand Down Expand Up @@ -546,8 +552,8 @@ function _applyRules(styleSheetContent: string, rulesClassName: string) {
}
}

colorThemeSchema.register();
fileIconThemeSchema.register();
registerColorThemeSchemas();
registerFileIconThemeSchemas();

class ConfigurationWriter {
constructor(@IConfigurationService private readonly configurationService: IConfigurationService) {
Expand Down Expand Up @@ -596,7 +602,7 @@ const iconThemeSettingSchema: IConfigurationPropertySchema = {
const colorCustomizationsSchema: IConfigurationPropertySchema = {
type: 'object',
description: nls.localize('workbenchColors', "Overrides colors from the currently selected color theme."),
allOf: [{ properties: colorThemeSchema.colorsSchema.properties }],
allOf: [{ $ref: workbenchColorsSchemaId }],
default: {},
defaultSnippets: [{
body: {
Expand Down Expand Up @@ -625,25 +631,32 @@ function tokenGroupSettings(description: string) {
type: 'string',
format: 'color-hex'
},
colorThemeSchema.tokenColorizationSettingSchema
{
$ref: textmateColorSettingsSchemaId
}
]
};
}

const tokenColorConfigurationProperties: IJSONSchemaMap = {
comments: tokenGroupSettings(nls.localize('editorColors.comments', "Sets the colors and styles for comments")),
strings: tokenGroupSettings(nls.localize('editorColors.strings', "Sets the colors and styles for strings literals.")),
keywords: tokenGroupSettings(nls.localize('editorColors.keywords', "Sets the colors and styles for keywords.")),
numbers: tokenGroupSettings(nls.localize('editorColors.numbers', "Sets the colors and styles for number literals.")),
types: tokenGroupSettings(nls.localize('editorColors.types', "Sets the colors and styles for type declarations and references.")),
functions: tokenGroupSettings(nls.localize('editorColors.functions', "Sets the colors and styles for functions declarations and references.")),
variables: tokenGroupSettings(nls.localize('editorColors.variables', "Sets the colors and styles for variables declarations and references.")),
[CUSTOM_EDITOR_SCOPE_COLORS_SETTING]: colorThemeSchema.tokenColorsSchema(nls.localize('editorColors.textMateRules', 'Sets colors and styles using textmate theming rules (advanced).'))
const tokenColorSchema: IJSONSchema = {
properties: {
comments: tokenGroupSettings(nls.localize('editorColors.comments', "Sets the colors and styles for comments")),
strings: tokenGroupSettings(nls.localize('editorColors.strings', "Sets the colors and styles for strings literals.")),
keywords: tokenGroupSettings(nls.localize('editorColors.keywords', "Sets the colors and styles for keywords.")),
numbers: tokenGroupSettings(nls.localize('editorColors.numbers', "Sets the colors and styles for number literals.")),
types: tokenGroupSettings(nls.localize('editorColors.types', "Sets the colors and styles for type declarations and references.")),
functions: tokenGroupSettings(nls.localize('editorColors.functions', "Sets the colors and styles for functions declarations and references.")),
variables: tokenGroupSettings(nls.localize('editorColors.variables', "Sets the colors and styles for variables declarations and references.")),
textMateRules: {
description: nls.localize('editorColors.textMateRules', 'Sets colors and styles using textmate theming rules (advanced).'),
$ref: textmateColorsSchemaId
}
}
};
const tokenColorCustomizationSchema: IConfigurationPropertySchema = {
description: nls.localize('editorColors', "Overrides editor colors and font style from the currently selected color theme."),
default: {},
allOf: [{ properties: tokenColorConfigurationProperties }]
allOf: [tokenColorSchema]
};
const tokenColorCustomizationConfiguration: IConfigurationNode = {
id: 'editor',
Expand Down

0 comments on commit 6220dcd

Please sign in to comment.