@@ -29,50 +29,65 @@ export class SemanticTokensProviderStyling {
2929 let metadata : number ;
3030 if ( entry ) {
3131 metadata = entry . metadata ;
32+ if ( this . _logService . getLevel ( ) === LogLevel . Trace ) {
33+ this . _logService . trace ( `SemanticTokensProviderStyling [CACHED] ${ tokenTypeIndex } / ${ tokenModifierSet } : foreground ${ TokenMetadata . getForeground ( metadata ) } , fontStyle ${ TokenMetadata . getFontStyle ( metadata ) . toString ( 2 ) } ` ) ;
34+ }
3235 } else {
33- const tokenType = this . _legend . tokenTypes [ tokenTypeIndex ] ;
36+ let tokenType = this . _legend . tokenTypes [ tokenTypeIndex ] ;
3437 const tokenModifiers : string [ ] = [ ] ;
35- let modifierSet = tokenModifierSet ;
36- for ( let modifierIndex = 0 ; modifierSet > 0 && modifierIndex < this . _legend . tokenModifiers . length ; modifierIndex ++ ) {
37- if ( modifierSet & 1 ) {
38- tokenModifiers . push ( this . _legend . tokenModifiers [ modifierIndex ] ) ;
39- }
40- modifierSet = modifierSet >> 1 ;
41- }
42-
43- const tokenStyle = this . _themeService . getColorTheme ( ) . getTokenStyleMetadata ( tokenType , tokenModifiers , languageId . language ) ;
44- if ( typeof tokenStyle === 'undefined' ) {
45- metadata = SemanticTokensProviderStylingConstants . NO_STYLING ;
46- } else {
47- metadata = 0 ;
48- if ( typeof tokenStyle . italic !== 'undefined' ) {
49- const italicBit = ( tokenStyle . italic ? FontStyle . Italic : 0 ) << MetadataConsts . FONT_STYLE_OFFSET ;
50- metadata |= italicBit | MetadataConsts . SEMANTIC_USE_ITALIC ;
51- }
52- if ( typeof tokenStyle . bold !== 'undefined' ) {
53- const boldBit = ( tokenStyle . bold ? FontStyle . Bold : 0 ) << MetadataConsts . FONT_STYLE_OFFSET ;
54- metadata |= boldBit | MetadataConsts . SEMANTIC_USE_BOLD ;
55- }
56- if ( typeof tokenStyle . underline !== 'undefined' ) {
57- const underlineBit = ( tokenStyle . underline ? FontStyle . Underline : 0 ) << MetadataConsts . FONT_STYLE_OFFSET ;
58- metadata |= underlineBit | MetadataConsts . SEMANTIC_USE_UNDERLINE ;
38+ if ( tokenType ) {
39+ let modifierSet = tokenModifierSet ;
40+ for ( let modifierIndex = 0 ; modifierSet > 0 && modifierIndex < this . _legend . tokenModifiers . length ; modifierIndex ++ ) {
41+ if ( modifierSet & 1 ) {
42+ tokenModifiers . push ( this . _legend . tokenModifiers [ modifierIndex ] ) ;
43+ }
44+ modifierSet = modifierSet >> 1 ;
5945 }
60- if ( tokenStyle . foreground ) {
61- const foregroundBits = ( tokenStyle . foreground ) << MetadataConsts . FOREGROUND_OFFSET ;
62- metadata |= foregroundBits | MetadataConsts . SEMANTIC_USE_FOREGROUND ;
46+ if ( modifierSet > 0 && this . _logService . getLevel ( ) === LogLevel . Trace ) {
47+ this . _logService . trace ( `SemanticTokensProviderStyling: unknown token modifier index: ${ tokenModifierSet . toString ( 2 ) } for legend: ${ JSON . stringify ( this . _legend . tokenModifiers ) } ` ) ;
48+ tokenModifiers . push ( 'not-in-legend' ) ;
6349 }
64- if ( metadata === 0 ) {
65- // Nothing!
50+
51+ const tokenStyle = this . _themeService . getColorTheme ( ) . getTokenStyleMetadata ( tokenType , tokenModifiers , languageId . language ) ;
52+ if ( typeof tokenStyle === 'undefined' ) {
6653 metadata = SemanticTokensProviderStylingConstants . NO_STYLING ;
54+ } else {
55+ metadata = 0 ;
56+ if ( typeof tokenStyle . italic !== 'undefined' ) {
57+ const italicBit = ( tokenStyle . italic ? FontStyle . Italic : 0 ) << MetadataConsts . FONT_STYLE_OFFSET ;
58+ metadata |= italicBit | MetadataConsts . SEMANTIC_USE_ITALIC ;
59+ }
60+ if ( typeof tokenStyle . bold !== 'undefined' ) {
61+ const boldBit = ( tokenStyle . bold ? FontStyle . Bold : 0 ) << MetadataConsts . FONT_STYLE_OFFSET ;
62+ metadata |= boldBit | MetadataConsts . SEMANTIC_USE_BOLD ;
63+ }
64+ if ( typeof tokenStyle . underline !== 'undefined' ) {
65+ const underlineBit = ( tokenStyle . underline ? FontStyle . Underline : 0 ) << MetadataConsts . FONT_STYLE_OFFSET ;
66+ metadata |= underlineBit | MetadataConsts . SEMANTIC_USE_UNDERLINE ;
67+ }
68+ if ( tokenStyle . foreground ) {
69+ const foregroundBits = ( tokenStyle . foreground ) << MetadataConsts . FOREGROUND_OFFSET ;
70+ metadata |= foregroundBits | MetadataConsts . SEMANTIC_USE_FOREGROUND ;
71+ }
72+ if ( metadata === 0 ) {
73+ // Nothing!
74+ metadata = SemanticTokensProviderStylingConstants . NO_STYLING ;
75+ }
76+ }
77+ } else {
78+ if ( this . _logService . getLevel ( ) === LogLevel . Trace ) {
79+ this . _logService . trace ( `SemanticTokensProviderStyling: unknown token type index: ${ tokenTypeIndex } for legend: ${ JSON . stringify ( this . _legend . tokenTypes ) } ` ) ;
6780 }
81+ metadata = SemanticTokensProviderStylingConstants . NO_STYLING ;
82+ tokenType = 'not-in-legend' ;
6883 }
6984 this . _hashTable . add ( tokenTypeIndex , tokenModifierSet , languageId . id , metadata ) ;
85+
86+ if ( this . _logService . getLevel ( ) === LogLevel . Trace ) {
87+ this . _logService . trace ( `SemanticTokensProviderStyling ${ tokenTypeIndex } (${ tokenType } ) / ${ tokenModifierSet } (${ tokenModifiers . join ( ' ' ) } ): foreground ${ TokenMetadata . getForeground ( metadata ) } , fontStyle ${ TokenMetadata . getFontStyle ( metadata ) . toString ( 2 ) } ` ) ;
88+ }
7089 }
71- if ( this . _logService . getLevel ( ) === LogLevel . Trace ) {
72- const type = this . _legend . tokenTypes [ tokenTypeIndex ] ;
73- const modifiers = tokenModifierSet ? ' ' + this . _legend . tokenModifiers . filter ( ( _ , i ) => tokenModifierSet & ( 1 << i ) ) . join ( ' ' ) : '' ;
74- this . _logService . trace ( `tokenStyleMetadata ${ entry ? '[CACHED] ' : '' } ${ type } ${ modifiers } : foreground ${ TokenMetadata . getForeground ( metadata ) } , fontStyle ${ TokenMetadata . getFontStyle ( metadata ) . toString ( 2 ) } ` ) ;
75- }
90+
7691 return metadata ;
7792 }
7893}
0 commit comments