src/vs/editor/common/encodedTokenAttributes.ts

193 LOC · 170 covered · 23 uncovered · 30 ranges · 3018 concepts · 9 introducers · 1469 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- encodedTokenAttributes.ts ×10
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > /**
7 > * Open ended enum at runtime
8 > */
9 > export const enum LanguageId {
10 > Null = 0,
11 > PlainText = 1
12 > }
13 >
14 > /**
15 > * A font style. Values are 2^x such that a bit mask can be used.
16 > */
17 > export const enum FontStyle {
18 > NotSet = -1,
19 > None = 0,
20 > Italic = 1,
21 > Bold = 2,
22 > Underline = 4,
23 > Strikethrough = 8,
24 > }
25 >
26 > /**
27 > * Open ended enum at runtime
28 > */
29 > export const enum ColorId {
30 > None = 0,
31 > DefaultForeground = 1,
32 > DefaultBackground = 2
33 > }
34 >
35 > /**
36 > * A standard token type.
37 > */
38 > export const enum StandardTokenType {
39 > Other = 0,
40 > Comment = 1,
41 > String = 2,
42 > RegEx = 3
43 > }
44 >
45 > /**
46 > * Helpers to manage the "collapsed" metadata of an entire StackElement stack.
47 > * The following assumptions have been made:
48 > * - languageId < 256 => needs 8 bits
49 > * - unique color count < 512 => needs 9 bits
50 > *
51 > * The binary format is:
52 > * - -------------------------------------------
53 > * 3322 2222 2222 1111 1111 1100 0000 0000
54 > * 1098 7654 3210 9876 5432 1098 7654 3210
55 > * - -------------------------------------------
56 > * xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
57 > * bbbb bbbb ffff ffff fFFF FBTT LLLL LLLL
58 > * - -------------------------------------------
59 > * - L = LanguageId (8 bits)
60 > * - T = StandardTokenType (2 bits)
61 > * - B = Balanced bracket (1 bit)
62 > * - F = FontStyle (4 bits)
63 > * - f = foreground color (9 bits)
64 > * - b = background color (8 bits)
65 > *
66 > */
67 > export const enum MetadataConsts {
68 > LANGUAGEID_MASK /* */ = 0b00000000_00000000_00000000_11111111,
69 > TOKEN_TYPE_MASK /* */ = 0b00000000_00000000_00000011_00000000,
70 > BALANCED_BRACKETS_MASK /* */ = 0b00000000_00000000_00000100_00000000,
71 > FONT_STYLE_MASK /* */ = 0b00000000_00000000_01111000_00000000,
72 > FOREGROUND_MASK /* */ = 0b00000000_11111111_10000000_00000000,
73 > BACKGROUND_MASK /* */ = 0b11111111_00000000_00000000_00000000,
74 >
75 > ITALIC_MASK /* */ = 0b00000000_00000000_00001000_00000000,
76 > BOLD_MASK /* */ = 0b00000000_00000000_00010000_00000000,
77 > UNDERLINE_MASK /* */ = 0b00000000_00000000_00100000_00000000,
78 > STRIKETHROUGH_MASK /* */ = 0b00000000_00000000_01000000_00000000,
79 >
80 > // Semantic tokens cannot set the language id, so we can
81 > // use the first 8 bits for control purposes
82 > SEMANTIC_USE_ITALIC /* */ = 0b00000000_00000000_00000000_00000001,
83 > SEMANTIC_USE_BOLD /* */ = 0b00000000_00000000_00000000_00000010,
84 > SEMANTIC_USE_UNDERLINE /* */ = 0b00000000_00000000_00000000_00000100,
85 > SEMANTIC_USE_STRIKETHROUGH /* */ = 0b00000000_00000000_00000000_00001000,
86 > SEMANTIC_USE_FOREGROUND /* */ = 0b00000000_00000000_00000000_00010000,
87 > SEMANTIC_USE_BACKGROUND /* */ = 0b00000000_00000000_00000000_00100000,
88 >
89 > LANGUAGEID_OFFSET = 0,
90 > TOKEN_TYPE_OFFSET = 8,
91 > BALANCED_BRACKETS_OFFSET = 10,
92 > FONT_STYLE_OFFSET = 11,
93 > FOREGROUND_OFFSET = 15,
94 > BACKGROUND_OFFSET = 24
95 > }
96 >
97 > /**
98 > */
99 > export class TokenMetadata {
100 >
101 > public static getLanguageId(metadata: number): LanguageId {
102 > return (metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET; encodedTokenAttributes.ts ×1
103 > }
105 > public static getTokenType(metadata: number): StandardTokenType {
106 > return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET; encodedTokenAttributes.ts ×1
107 > }
109 > public static containsBalancedBrackets(metadata: number): boolean {
110 > return (metadata & MetadataConsts.BALANCED_BRACKETS_MASK) !== 0; tokenizer.ts ×13
111 > }
113 > public static getFontStyle(metadata: number): FontStyle {
114 > return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET; encodedTokenAttributes.ts ×1
115 > }
117 > public static getForeground(metadata: number): ColorId {
118 > return (metadata & MetadataConsts.FOREGROUND_MASK) >>> MetadataConsts.FOREGROUND_OFFSET; encodedTokenAttributes.ts ×1
119 > }
121 > public static getBackground(metadata: number): ColorId {
122 return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET;
123 }
125 > public static getClassNameFromMetadata(metadata: number): string {
126 > const foreground = this.getForeground(metadata); encodedTokenAttributes.ts ×5
127 > let className = 'mtk' + foreground;
128 >
129 > const fontStyle = this.getFontStyle(metadata);
130 > if (fontStyle & FontStyle.Italic) {
131 className += ' mtki';
132 }
133 > if (fontStyle & FontStyle.Bold) { encodedTokenAttributes.ts ×5
134 className += ' mtkb';
135 }
136 > if (fontStyle & FontStyle.Underline) { encodedTokenAttributes.ts ×5
137 className += ' mtku';
138 }
139 > if (fontStyle & FontStyle.Strikethrough) { encodedTokenAttributes.ts ×5
140 className += ' mtks';
141 }
143 > return className;
144 > }
146 > public static getInlineStyleFromMetadata(metadata: number, colorMap: string[]): string {
147 > const foreground = this.getForeground(metadata); textToHtmlTokenizer.ts ×11
148 > const fontStyle = this.getFontStyle(metadata);
149 >
150 > let result = `color: ${colorMap[foreground]};`;
151 > if (fontStyle & FontStyle.Italic) {
152 > result += 'font-style: italic;'; encodedTokenAttributes.ts ×4
153 > }
154 > if (fontStyle & FontStyle.Bold) { textToHtmlTokenizer.ts ×11
155 > result += 'font-weight: bold;'; encodedTokenAttributes.ts ×4
156 > }
157 > let textDecoration = ''; textToHtmlTokenizer.ts ×11
158 > if (fontStyle & FontStyle.Underline) {
159 > textDecoration += ' underline'; encodedTokenAttributes.ts ×4
160 > }
161 > if (fontStyle & FontStyle.Strikethrough) { textToHtmlTokenizer.ts ×11
162 textDecoration += ' line-through';
163 }
164 > if (textDecoration) { textToHtmlTokenizer.ts ×11
165 > result += `text-decoration:${textDecoration};`; encodedTokenAttributes.ts ×4
166 >
167 > }
168 > return result; textToHtmlTokenizer.ts ×11
169 > }
171 > public static getPresentationFromMetadata(metadata: number): ITokenPresentation {
172 const foreground = this.getForeground(metadata);
173 const fontStyle = this.getFontStyle(metadata);
174
175 return {
176 foreground: foreground,
177 italic: Boolean(fontStyle & FontStyle.Italic),
178 bold: Boolean(fontStyle & FontStyle.Bold),
179 underline: Boolean(fontStyle & FontStyle.Underline),
180 strikethrough: Boolean(fontStyle & FontStyle.Strikethrough),
181 };
182 }
184 >
185 > /**
186 > */
187 > export interface ITokenPresentation {
188 > foreground: ColorId;
189 > italic: boolean;
190 > bold: boolean;
191 > underline: boolean;
192 > strikethrough: boolean;
193 > }