Skip to content

Commit 412ee9a

Browse files
committed
Make editor.tokenColorCustomizationsExperimental offical. Fixes microsoft#96267
1 parent 696dca7 commit 412ee9a

7 files changed

Lines changed: 186 additions & 105 deletions

File tree

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const typeAndModifierIdPattern = `^${idPattern}$`;
2424

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

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

2929
export interface TokenSelector {
3030
match(type: string, modifiers: string[], language: string): number;
@@ -124,18 +124,18 @@ export interface TokenStyleDefaults {
124124
hc?: TokenStyleValue;
125125
}
126126

127-
export interface TokenStylingDefaultRule {
127+
export interface SemanticTokenDefaultRule {
128128
selector: TokenSelector;
129129
defaults: TokenStyleDefaults;
130130
}
131131

132-
export interface TokenStylingRule {
132+
export interface SemanticTokenRule {
133133
style: TokenStyle;
134134
selector: TokenSelector;
135135
}
136136

137-
export namespace TokenStylingRule {
138-
export function fromJSONObject(registry: ITokenClassificationRegistry, o: any): TokenStylingRule | undefined {
137+
export namespace SemanticTokenRule {
138+
export function fromJSONObject(registry: ITokenClassificationRegistry, o: any): SemanticTokenRule | undefined {
139139
if (o && typeof o._selector === 'string' && o._style) {
140140
const style = TokenStyle.fromJSONObject(o._style);
141141
if (style) {
@@ -147,21 +147,21 @@ export namespace TokenStylingRule {
147147
}
148148
return undefined;
149149
}
150-
export function toJSONObject(rule: TokenStylingRule): any {
150+
export function toJSONObject(rule: SemanticTokenRule): any {
151151
return {
152152
_selector: rule.selector.id,
153153
_style: TokenStyle.toJSONObject(rule.style)
154154
};
155155
}
156-
export function equals(r1: TokenStylingRule | undefined, r2: TokenStylingRule | undefined) {
156+
export function equals(r1: SemanticTokenRule | undefined, r2: SemanticTokenRule | undefined) {
157157
if (r1 === r2) {
158158
return true;
159159
}
160160
return r1 !== undefined && r2 !== undefined
161161
&& r1.selector && r2.selector && r1.selector.id === r2.selector.id
162162
&& TokenStyle.equals(r1.style, r2.style);
163163
}
164-
export function is(r: any): r is TokenStylingRule {
164+
export function is(r: any): r is SemanticTokenRule {
165165
return r && r.selector && typeof r.selector.selectorString === 'string' && TokenStyle.is(r.style);
166166
}
167167
}
@@ -239,7 +239,7 @@ export interface ITokenClassificationRegistry {
239239
/**
240240
* The styling rules to used when a schema does not define any styling rules.
241241
*/
242-
getTokenStylingDefaultRules(): TokenStylingDefaultRule[];
242+
getTokenStylingDefaultRules(): SemanticTokenDefaultRule[];
243243

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

261-
private tokenStylingDefaultRules: TokenStylingDefaultRule[] = [];
261+
private tokenStylingDefaultRules: SemanticTokenDefaultRule[] = [];
262262

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

265-
private tokenStylingSchema: IJSONSchema & { properties: IJSONSchemaMap } = {
265+
private tokenStylingSchema: IJSONSchema & { properties: IJSONSchemaMap, patternProperties: IJSONSchemaMap } = {
266266
type: 'object',
267267
properties: {},
268-
additionalProperties: getStylingSchemeEntry(),
268+
patternProperties: {
269+
[selectorPattern]: getStylingSchemeEntry()
270+
},
271+
//errorMessage: nls.localize('schema.token.errors', 'Valid token selectors have the form (*|tokenType)(.tokenModifier)*(:tokenLanguage)?.'),
272+
additionalProperties: false,
269273
definitions: {
270274
style: {
271275
type: 'object',
@@ -325,7 +329,8 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
325329
let tokenStyleContribution: TokenTypeOrModifierContribution = { num, id, superType, description, deprecationMessage };
326330
this.tokenTypeById[id] = tokenStyleContribution;
327331

328-
this.tokenStylingSchema.properties[id] = getStylingSchemeEntry(description, deprecationMessage);
332+
const stylingSchemeEntry = getStylingSchemeEntry(description, deprecationMessage);
333+
this.tokenStylingSchema.properties[id] = stylingSchemeEntry;
329334
this.typeHierarchy = {};
330335
}
331336

@@ -413,7 +418,7 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
413418
return this.tokenStylingSchema;
414419
}
415420

416-
public getTokenStylingDefaultRules(): TokenStylingDefaultRule[] {
421+
public getTokenStylingDefaultRules(): SemanticTokenDefaultRule[] {
417422
return this.tokenStylingDefaultRules;
418423
}
419424

src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { ITextMateService, IGrammar, IToken, StackElement } from 'vs/workbench/s
2727
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
2828
import { CancellationTokenSource } from 'vs/base/common/cancellation';
2929
import { ColorThemeData, TokenStyleDefinitions, TokenStyleDefinition, TextMateThemingRuleDefinitions } from 'vs/workbench/services/themes/common/colorThemeData';
30-
import { TokenStylingRule, TokenStyleData, TokenStyle } from 'vs/platform/theme/common/tokenClassificationRegistry';
30+
import { SemanticTokenRule, TokenStyleData, TokenStyle } from 'vs/platform/theme/common/tokenClassificationRegistry';
3131
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3232

3333
export interface IEditorSemanticHighlightingOptions {
@@ -557,7 +557,7 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget {
557557
return `${escape(scopesDefinition.scope.join(' '))}<br><code class="tiw-theme-selector">${strScopes}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
558558
}
559559
return '';
560-
} else if (TokenStylingRule.is(definition)) {
560+
} else if (SemanticTokenRule.is(definition)) {
561561
const scope = theme.getTokenStylingRuleScope(definition);
562562
if (scope === 'setting') {
563563
return `User settings: ${definition.selector.id} - ${this._renderStyleProperty(definition.style, property)}`;

src/vs/workbench/services/themes/browser/workbenchThemeService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
218218
this.currentColorTheme.setCustomTokenColors(this.settings.tokenColorCustomizations);
219219
hasColorChanges = true;
220220
}
221-
if (e.affectsConfiguration(ThemeSettings.TOKEN_COLOR_CUSTOMIZATIONS_EXPERIMENTAL)) {
222-
this.currentColorTheme.setCustomTokenStyleRules(this.settings.tokenStylesCustomizations);
221+
if (e.affectsConfiguration(ThemeSettings.SEMANTIC_TOKEN_COLOR_CUSTOMIZATIONS) || e.affectsConfiguration(ThemeSettings.TOKEN_COLOR_CUSTOMIZATIONS_EXPERIMENTAL)) {
222+
this.currentColorTheme.setCustomSemanticTokenColors(this.settings.semanticTokenColorCustomizations, this.settings.experimentalSemanticTokenColorCustomizations);
223223
hasColorChanges = true;
224224
}
225225
if (hasColorChanges) {

0 commit comments

Comments
 (0)