encodedTokenAttributes.ts ×10

Frontier kind: Code frontier

unlabeled · c_f0e79088f372

1469 tests · 3506 LOC · 19 files · introduces 0 tests · 128 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
10 ranges128 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
490 ranges3506 lines · 19 files · Browse complete extent
All tests (intent)
1469 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 128 introduced LOC across 10 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/encodedTokenAttributes.ts 128 introduced LOC · 10 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- encodedTokenAttributes.ts
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;
103 }
105 > public static getTokenType(metadata: number): StandardTokenType {
106 return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET;
107 }
109 > public static containsBalancedBrackets(metadata: number): boolean {
110 return (metadata & MetadataConsts.BALANCED_BRACKETS_MASK) !== 0;
111 }
113 > public static getFontStyle(metadata: number): FontStyle {
114 return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET;
115 }
117 > public static getForeground(metadata: number): ColorId {
118 return (metadata & MetadataConsts.FOREGROUND_MASK) >>> MetadataConsts.FOREGROUND_OFFSET;
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);
127 let className = 'mtk' + foreground;
143 return className;
144 }
146 > public static getInlineStyleFromMetadata(metadata: number, colorMap: string[]): string {
147 const foreground = this.getForeground(metadata);
148 const fontStyle = this.getFontStyle(metadata);
168 return result;
169 }
171 > public static getPresentationFromMetadata(metadata: number): ITokenPresentation {
172 const foreground = this.getForeground(metadata);
173 const fontStyle = this.getFontStyle(metadata);
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 > }