@@ -13,21 +13,15 @@ import { Event, Emitter } from 'vs/base/common/event';
1313import { IJSONSchema , IJSONSchemaMap } from 'vs/base/common/jsonSchema' ;
1414
1515export const TOKEN_TYPE_WILDCARD = '*' ;
16- export const TOKEN_TYPE_WILDCARD_NUM = - 1 ;
1716
1817// qualified string [type|*](.modifier)*
1918export type TokenClassificationString = string ;
2019
2120export const typeAndModifierIdPattern = '^\\w+[-_\\w+]*$' ;
2221export const fontStylePattern = '^(\\s*(-?italic|-?bold|-?underline))*\\s*$' ;
2322
24- export interface TokenClassification {
25- type : number ;
26- modifiers : number ;
27- }
28-
2923export interface TokenSelector {
30- match ( classification : TokenClassification ) : number ;
24+ match ( type : string , modifiers : string [ ] ) : number ;
3125 asString ( ) : string ;
3226}
3327
@@ -138,8 +132,6 @@ export interface ITokenClassificationRegistry {
138132 */
139133 registerTokenModifier ( id : string , description : string ) : void ;
140134
141- getTokenClassification ( type : string , modifiers : string [ ] ) : TokenClassification | undefined ;
142-
143135 /**
144136 * Parses a token selector from a selector string.
145137 * @param selectorString selector string in the form (*|type)(.modifier)*
@@ -241,8 +233,6 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
241233 constructor ( ) {
242234 this . tokenTypeById = { } ;
243235 this . tokenModifierById = { } ;
244-
245- this . tokenTypeById [ TOKEN_TYPE_WILDCARD ] = { num : TOKEN_TYPE_WILDCARD_NUM , id : TOKEN_TYPE_WILDCARD , description : '' , deprecationMessage : undefined } ;
246236 }
247237
248238 public registerTokenType ( id : string , description : string , deprecationMessage ?: string ) : void {
@@ -270,42 +260,27 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
270260 this . tokenStylingSchema . properties [ `*.${ id } ` ] = getStylingSchemeEntry ( description , deprecationMessage ) ;
271261 }
272262
273- public getTokenClassification ( type : string , modifiers : string [ ] ) : TokenClassification | undefined {
274- const tokenTypeDesc = this . tokenTypeById [ type ] ;
275- if ( ! tokenTypeDesc ) {
276- return undefined ;
277- }
278- let allModifierBits = 0 ;
279- for ( const modifier of modifiers ) {
280- const tokenModifierDesc = this . tokenModifierById [ modifier ] ;
281- if ( tokenModifierDesc ) {
282- allModifierBits |= tokenModifierDesc . num ;
283- }
284- }
285- return { type : tokenTypeDesc . num , modifiers : allModifierBits } ;
286- }
287-
288-
289263 public parseTokenSelector ( selectorString : string ) : TokenSelector {
290- const [ type , ...modifiers ] = selectorString . split ( '.' ) ;
264+ const [ selectorType , ...selectorModifiers ] = selectorString . split ( '.' ) ;
291265
292- const selectorClassification = this . getTokenClassification ( type , modifiers ) ;
293- if ( ! selectorClassification ) {
266+ if ( ! selectorType ) {
294267 return {
295268 match : ( ) => - 1 ,
296269 asString : ( ) => selectorString
297270 } ;
298271 }
299- const score = getTokenStylingScore ( selectorClassification ) ;
272+ const score = selectorModifiers . length + ( ( selectorString !== TOKEN_TYPE_WILDCARD ) ? 1 : 0 ) ;
300273
301274 return {
302- match : ( classification : TokenClassification ) => {
303- if ( selectorClassification . type !== TOKEN_TYPE_WILDCARD_NUM && selectorClassification . type !== classification . type ) {
275+ match : ( type : string , modifiers : string [ ] ) => {
276+ if ( selectorType !== TOKEN_TYPE_WILDCARD && selectorType !== type ) {
304277 return - 1 ;
305278 }
306- const selectorModifier = selectorClassification . modifiers ;
307- if ( ( classification . modifiers & selectorModifier ) !== selectorModifier ) {
308- return - 1 ;
279+ // all selector modifiers must be present
280+ for ( const selectorModifier of selectorModifiers ) {
281+ if ( modifiers . indexOf ( selectorModifier ) === - 1 ) {
282+ return - 1 ;
283+ }
309284 }
310285 return score ;
311286 } ,
@@ -432,16 +407,6 @@ export function getTokenClassificationRegistry(): ITokenClassificationRegistry {
432407 return tokenClassificationRegistry ;
433408}
434409
435- function bitCount ( u : number ) {
436- // https://blogs.msdn.microsoft.com/jeuge/2005/06/08/bit-fiddling-3/
437- const uCount = u - ( ( u >> 1 ) & 0o33333333333 ) - ( ( u >> 2 ) & 0o11111111111 ) ;
438- return ( ( uCount + ( uCount >> 3 ) ) & 0o30707070707 ) % 63 ;
439- }
440-
441- function getTokenStylingScore ( classification : TokenClassification ) {
442- return bitCount ( classification . modifiers ) + ( ( classification . type !== TOKEN_TYPE_WILDCARD_NUM ) ? 1 : 0 ) ;
443- }
444-
445410function getStylingSchemeEntry ( description ?: string , deprecationMessage ?: string ) : IJSONSchema {
446411 return {
447412 description,
0 commit comments