Skip to content

Commit

Permalink
Make editor.tokenColorCustomizationsExperimental offical. Fixes #96267
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Apr 27, 2020
1 parent 696dca7 commit 412ee9a
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 105 deletions.
33 changes: 19 additions & 14 deletions src/vs/platform/theme/common/tokenClassificationRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const typeAndModifierIdPattern = `^${idPattern}$`;

export const selectorPattern = `^(${idPattern}|\\*)(\\${CLASSIFIER_MODIFIER_SEPARATOR}${idPattern})*(\\${TOKEN_CLASSIFIER_LANGUAGE_SEPARATOR}${idPattern})?$`;

export const fontStylePattern = '^(\\s*(-?italic|-?bold|-?underline))*\\s*$';
export const fontStylePattern = '^(\\s*(italic|bold|underline))*\\s*$';

export interface TokenSelector {
match(type: string, modifiers: string[], language: string): number;
Expand Down Expand Up @@ -124,18 +124,18 @@ export interface TokenStyleDefaults {
hc?: TokenStyleValue;
}

export interface TokenStylingDefaultRule {
export interface SemanticTokenDefaultRule {
selector: TokenSelector;
defaults: TokenStyleDefaults;
}

export interface TokenStylingRule {
export interface SemanticTokenRule {
style: TokenStyle;
selector: TokenSelector;
}

export namespace TokenStylingRule {
export function fromJSONObject(registry: ITokenClassificationRegistry, o: any): TokenStylingRule | undefined {
export namespace SemanticTokenRule {
export function fromJSONObject(registry: ITokenClassificationRegistry, o: any): SemanticTokenRule | undefined {
if (o && typeof o._selector === 'string' && o._style) {
const style = TokenStyle.fromJSONObject(o._style);
if (style) {
Expand All @@ -147,21 +147,21 @@ export namespace TokenStylingRule {
}
return undefined;
}
export function toJSONObject(rule: TokenStylingRule): any {
export function toJSONObject(rule: SemanticTokenRule): any {
return {
_selector: rule.selector.id,
_style: TokenStyle.toJSONObject(rule.style)
};
}
export function equals(r1: TokenStylingRule | undefined, r2: TokenStylingRule | undefined) {
export function equals(r1: SemanticTokenRule | undefined, r2: SemanticTokenRule | undefined) {
if (r1 === r2) {
return true;
}
return r1 !== undefined && r2 !== undefined
&& r1.selector && r2.selector && r1.selector.id === r2.selector.id
&& TokenStyle.equals(r1.style, r2.style);
}
export function is(r: any): r is TokenStylingRule {
export function is(r: any): r is SemanticTokenRule {
return r && r.selector && typeof r.selector.selectorString === 'string' && TokenStyle.is(r.style);
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ export interface ITokenClassificationRegistry {
/**
* The styling rules to used when a schema does not define any styling rules.
*/
getTokenStylingDefaultRules(): TokenStylingDefaultRule[];
getTokenStylingDefaultRules(): SemanticTokenDefaultRule[];

/**
* JSON schema for an object to assign styling to token classifications
Expand All @@ -258,14 +258,18 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
private tokenTypeById: { [key: string]: TokenTypeOrModifierContribution };
private tokenModifierById: { [key: string]: TokenTypeOrModifierContribution };

private tokenStylingDefaultRules: TokenStylingDefaultRule[] = [];
private tokenStylingDefaultRules: SemanticTokenDefaultRule[] = [];

private typeHierarchy: { [id: string]: string[] };

private tokenStylingSchema: IJSONSchema & { properties: IJSONSchemaMap } = {
private tokenStylingSchema: IJSONSchema & { properties: IJSONSchemaMap, patternProperties: IJSONSchemaMap } = {
type: 'object',
properties: {},
additionalProperties: getStylingSchemeEntry(),
patternProperties: {
[selectorPattern]: getStylingSchemeEntry()
},
//errorMessage: nls.localize('schema.token.errors', 'Valid token selectors have the form (*|tokenType)(.tokenModifier)*(:tokenLanguage)?.'),
additionalProperties: false,
definitions: {
style: {
type: 'object',
Expand Down Expand Up @@ -325,7 +329,8 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
let tokenStyleContribution: TokenTypeOrModifierContribution = { num, id, superType, description, deprecationMessage };
this.tokenTypeById[id] = tokenStyleContribution;

this.tokenStylingSchema.properties[id] = getStylingSchemeEntry(description, deprecationMessage);
const stylingSchemeEntry = getStylingSchemeEntry(description, deprecationMessage);
this.tokenStylingSchema.properties[id] = stylingSchemeEntry;
this.typeHierarchy = {};
}

Expand Down Expand Up @@ -413,7 +418,7 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
return this.tokenStylingSchema;
}

public getTokenStylingDefaultRules(): TokenStylingDefaultRule[] {
public getTokenStylingDefaultRules(): SemanticTokenDefaultRule[] {
return this.tokenStylingDefaultRules;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ITextMateService, IGrammar, IToken, StackElement } from 'vs/workbench/s
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { ColorThemeData, TokenStyleDefinitions, TokenStyleDefinition, TextMateThemingRuleDefinitions } from 'vs/workbench/services/themes/common/colorThemeData';
import { TokenStylingRule, TokenStyleData, TokenStyle } from 'vs/platform/theme/common/tokenClassificationRegistry';
import { SemanticTokenRule, TokenStyleData, TokenStyle } from 'vs/platform/theme/common/tokenClassificationRegistry';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';

export interface IEditorSemanticHighlightingOptions {
Expand Down Expand Up @@ -557,7 +557,7 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget {
return `${escape(scopesDefinition.scope.join(' '))}<br><code class="tiw-theme-selector">${strScopes}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
}
return '';
} else if (TokenStylingRule.is(definition)) {
} else if (SemanticTokenRule.is(definition)) {
const scope = theme.getTokenStylingRuleScope(definition);
if (scope === 'setting') {
return `User settings: ${definition.selector.id} - ${this._renderStyleProperty(definition.style, property)}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this.currentColorTheme.setCustomTokenColors(this.settings.tokenColorCustomizations);
hasColorChanges = true;
}
if (e.affectsConfiguration(ThemeSettings.TOKEN_COLOR_CUSTOMIZATIONS_EXPERIMENTAL)) {
this.currentColorTheme.setCustomTokenStyleRules(this.settings.tokenStylesCustomizations);
if (e.affectsConfiguration(ThemeSettings.SEMANTIC_TOKEN_COLOR_CUSTOMIZATIONS) || e.affectsConfiguration(ThemeSettings.TOKEN_COLOR_CUSTOMIZATIONS_EXPERIMENTAL)) {
this.currentColorTheme.setCustomSemanticTokenColors(this.settings.semanticTokenColorCustomizations, this.settings.experimentalSemanticTokenColorCustomizations);
hasColorChanges = true;
}
if (hasColorChanges) {
Expand Down
Loading

0 comments on commit 412ee9a

Please sign in to comment.