sparseTokensStore.ts ×10

Frontier kind: Code frontier

unlabeled · c_c7d2fc9a081a

13 tests · 39184 LOC · 240 files · introduces 0 tests · 83 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges83 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
4554 ranges39184 lines · 240 files · Browse complete extent
All tests (intent)
13 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.

2 files ranked by introduced lines: 83 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/tokens/sparseTokensStore.ts 64 introduced LOC · 10 ranges

Open complete file

142 return aTokens;
143 }
145 > const pieceIndex = SparseTokensStore._findFirstPieceWithLine(pieces, lineNumber);
146 > const bTokens = pieces[pieceIndex].getLineTokens(lineNumber);
147 >
148 > if (!bTokens) {
149 return aTokens;
150 }
152 > const aLen = aTokens.getCount();
153 > const bLen = bTokens.getCount();
154 >
155 > let aIndex = 0;
156 > const result: number[] = [];
157 > let resultLen = 0;
158 > let lastEndOffset = 0;
159 >
160 > const emitToken = (endOffset: number, metadata: number) => {
161 > if (endOffset <= lastEndOffset) {
162 return;
163 }
164 > lastEndOffset = endOffset; sparseTokensStore.ts
165 > result[resultLen++] = endOffset;
166 > result[resultLen++] = metadata;
167 > };
168 >
169 > for (let bIndex = 0; bIndex < bLen; bIndex++) {
170 > // bTokens is not validated yet, but aTokens is. We want to make sure that the LineTokens we return
171 > // are valid, so we clamp the ranges to ensure that.
172 > const bStartCharacter = Math.min(bTokens.getStartCharacter(bIndex), aTokens.getTextLength());
173 > const bEndCharacter = Math.min(bTokens.getEndCharacter(bIndex), aTokens.getTextLength());
174 > const bMetadata = bTokens.getMetadata(bIndex);
175 >
176 > const bMask = (
177 > ((bMetadata & MetadataConsts.SEMANTIC_USE_ITALIC) ? MetadataConsts.ITALIC_MASK : 0)
178 > | ((bMetadata & MetadataConsts.SEMANTIC_USE_BOLD) ? MetadataConsts.BOLD_MASK : 0)
179 > | ((bMetadata & MetadataConsts.SEMANTIC_USE_UNDERLINE) ? MetadataConsts.UNDERLINE_MASK : 0)
180 > | ((bMetadata & MetadataConsts.SEMANTIC_USE_STRIKETHROUGH) ? MetadataConsts.STRIKETHROUGH_MASK : 0)
181 > | ((bMetadata & MetadataConsts.SEMANTIC_USE_FOREGROUND) ? MetadataConsts.FOREGROUND_MASK : 0)
182 > | ((bMetadata & MetadataConsts.SEMANTIC_USE_BACKGROUND) ? MetadataConsts.BACKGROUND_MASK : 0)
183 > ) >>> 0;
184 > const aMask = (~bMask) >>> 0;
185 >
186 > // push any token from `a` that is before `b`
187 > while (aIndex < aLen && aTokens.getEndOffset(aIndex) <= bStartCharacter) {
188 emitToken(aTokens.getEndOffset(aIndex), aTokens.getMetadata(aIndex));
189 aIndex++;
190 }
192 > // push the token from `a` if it intersects the token from `b`
193 > if (aIndex < aLen && aTokens.getStartOffset(aIndex) < bStartCharacter) {
194 > emitToken(bStartCharacter, aTokens.getMetadata(aIndex));
195 > }
196 >
197 > // skip any tokens from `a` that are contained inside `b`
198 > while (aIndex < aLen && aTokens.getEndOffset(aIndex) < bEndCharacter) {
199 emitToken(aTokens.getEndOffset(aIndex), (aTokens.getMetadata(aIndex) & aMask) | (bMetadata & bMask));
200 aIndex++;
201 }
203 > if (aIndex < aLen) {
204 > emitToken(bEndCharacter, (aTokens.getMetadata(aIndex) & aMask) | (bMetadata & bMask));
205 > if (aTokens.getEndOffset(aIndex) === bEndCharacter) {
206 // `a` ends exactly at the same spot as `b`!
207 aIndex++;
208 }
209 > } else { sparseTokensStore.ts
210 const aMergeIndex = Math.min(Math.max(0, aIndex - 1), aLen - 1);
211
213 emitToken(bEndCharacter, (aTokens.getMetadata(aMergeIndex) & aMask) | (bMetadata & bMask));
214 }
216 >
217 > // push the remaining tokens from `a`
218 > while (aIndex < aLen) {
219 emitToken(aTokens.getEndOffset(aIndex), aTokens.getMetadata(aIndex));
220 aIndex++;
221 }
223 > return new LineTokens(new Uint32Array(result), aTokens.getLineContent(), this._languageIdCodec);
224 }
225
226 private static _findFirstPieceWithLine(pieces: SparseMultilineTokens[], lineNumber: number): number {
227 > let low = 0; sparseTokensStore.ts
228 > let high = pieces.length - 1;
229 >
230 > while (low < high) {
231 let mid = low + Math.floor((high - low) / 2);
232
244
245 return low;
247
248 public acceptEdit(range: IRange, eolCount: number, firstLineLength: number, lastLineLength: number, firstCharCode: number): void {
src/vs/editor/common/tokens/sparseMultilineTokens.ts 19 introduced LOC · 9 ranges

Open complete file

57
58 public getLineTokens(lineNumber: number): SparseLineTokens | null {
59 > if (this._startLineNumber <= lineNumber && lineNumber <= this._endLineNumber) { sparseMultilineTokens.ts
60 > return this._tokens.getLineTokens(lineNumber - this._startLineNumber);
61 > }
62 return null;
64
65 public getRange(): Range | null {
235
236 public getLineTokens(deltaLine: number): SparseLineTokens | null {
237 > let low = 0; sparseMultilineTokens.ts
238 > let high = this._getTokenCount() - 1;
239 >
240 > while (low < high) {
241 const mid = low + Math.floor((high - low) / 2);
242 const midDeltaLine = this._getDeltaLine(mid);
597
598 constructor(tokens: Uint32Array) {
599 > this._tokens = tokens; sparseMultilineTokens.ts
600 > }
601
602 public getCount(): number {
603 > return this._tokens.length / 4; sparseMultilineTokens.ts
604 > }
605
606 public getStartCharacter(tokenIndex: number): number {
607 > return this._tokens[4 * tokenIndex + 1]; sparseMultilineTokens.ts
608 > }
609
610 public getEndCharacter(tokenIndex: number): number {
611 > return this._tokens[4 * tokenIndex + 2]; sparseMultilineTokens.ts
612 > }
613
614 public getMetadata(tokenIndex: number): number {
615 > return this._tokens[4 * tokenIndex + 3]; sparseMultilineTokens.ts
616 > }
617 }