@@ -142,9 +142,9 @@ export interface ITokenClassificationRegistry {
142142 getTokenModifiers ( ) : TokenTypeOrModifierContribution [ ] ;
143143
144144 /**
145- * Resolves a token classification against the given rules and default rules from the registry .
145+ * The styling rules to used when a schema does not define any styling rules .
146146 */
147- resolveTokenStyle ( classification : TokenClassification , themingRules : TokenStylingRule [ ] | undefined , customThemingRules : TokenStylingRule [ ] , theme : ITheme ) : TokenStyle | undefined ;
147+ getTokenStylingDefaultRules ( ) : TokenStylingDefaultRule [ ] ;
148148
149149 /**
150150 * JSON schema for an object to assign styling to token classifications
@@ -271,87 +271,13 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
271271 return Object . keys ( this . tokenModifierById ) . map ( id => this . tokenModifierById [ id ] ) ;
272272 }
273273
274- public resolveTokenStyle ( classification : TokenClassification , themingRules : TokenStylingRule [ ] | undefined , customThemingRules : TokenStylingRule [ ] , theme : ITheme ) : TokenStyle | undefined {
275- let result : any = {
276- foreground : undefined ,
277- bold : undefined ,
278- underline : undefined ,
279- italic : undefined
280- } ;
281- let score = {
282- foreground : - 1 ,
283- bold : - 1 ,
284- underline : - 1 ,
285- italic : - 1
286- } ;
287-
288- function _processStyle ( matchScore : number , style : TokenStyle ) {
289- if ( style . foreground && score . foreground <= matchScore ) {
290- score . foreground = matchScore ;
291- result . foreground = style . foreground ;
292- }
293- for ( let p of [ 'bold' , 'underline' , 'italic' ] ) {
294- const property = p as keyof TokenStyle ;
295- const info = style [ property ] ;
296- if ( info !== undefined ) {
297- if ( score [ property ] <= matchScore ) {
298- score [ property ] = matchScore ;
299- result [ property ] = info ;
300- }
301- }
302- }
303- }
304- if ( themingRules === undefined ) {
305- for ( const rule of this . tokenStylingDefaultRules ) {
306- const matchScore = match ( rule , classification ) ;
307- if ( matchScore >= 0 ) {
308- let style = theme . resolveScopes ( rule . defaults . scopesToProbe ) ;
309- if ( ! style ) {
310- style = this . resolveTokenStyleValue ( rule . defaults [ theme . type ] , theme ) ;
311- }
312- if ( style ) {
313- _processStyle ( matchScore , style ) ;
314- }
315- }
316- }
317- } else {
318- for ( const rule of themingRules ) {
319- const matchScore = match ( rule , classification ) ;
320- if ( matchScore >= 0 ) {
321- _processStyle ( matchScore , rule . value ) ;
322- }
323- }
324- }
325- for ( const rule of customThemingRules ) {
326- const matchScore = match ( rule , classification ) ;
327- if ( matchScore >= 0 ) {
328- _processStyle ( matchScore , rule . value ) ;
329- }
330- }
331- return TokenStyle . fromData ( result ) ;
332- }
333-
334- /**
335- * @param tokenStyleValue Resolve a tokenStyleValue in the context of a theme
336- */
337- private resolveTokenStyleValue ( tokenStyleValue : TokenStyleValue | null , theme : ITheme ) : TokenStyle | undefined {
338- if ( tokenStyleValue === null ) {
339- return undefined ;
340- } else if ( typeof tokenStyleValue === 'string' ) {
341- const classification = this . getTokenClassificationFromString ( tokenStyleValue ) ;
342- if ( classification ) {
343- return theme . getTokenStyle ( classification ) ;
344- }
345- } else if ( typeof tokenStyleValue === 'object' ) {
346- return tokenStyleValue ;
347- }
348- return undefined ;
349- }
350-
351274 public getTokenStylingSchema ( ) : IJSONSchema {
352275 return this . tokenStylingSchema ;
353276 }
354277
278+ public getTokenStylingDefaultRules ( ) : TokenStylingDefaultRule [ ] {
279+ return this . tokenStylingDefaultRules ;
280+ }
355281
356282 public toString ( ) {
357283 let sorter = ( a : string , b : string ) => {
@@ -368,7 +294,7 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
368294
369295}
370296
371- function match ( themeSelector : TokenStylingRule | TokenStylingDefaultRule , classification : TokenClassification ) : number {
297+ export function matchTokenStylingRule ( themeSelector : TokenStylingRule | TokenStylingDefaultRule , classification : TokenClassification ) : number {
372298 const selectorType = themeSelector . classification . type ;
373299 if ( selectorType !== TOKEN_TYPE_WILDCARD_NUM && selectorType !== classification . type ) {
374300 return - 1 ;
0 commit comments