annotations.ts ×15

Frontier kind: Code frontier

unlabeled · c_f1753f1ca02e

884 tests · 6312 LOC · 36 files · introduces 0 tests · 110 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges110 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1027 ranges6312 lines · 36 files · Browse complete extent
All tests (intent)
884 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: 110 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/tokens/annotations.ts 110 introduced LOC · 15 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- annotations.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 > import { binarySearch2 } from '../../../../base/common/arrays.js';
7 > import { StringEdit } from '../../core/edits/stringEdit.js';
8 > import { OffsetRange } from '../../core/ranges/offsetRange.js';
9 >
10 > export interface IAnnotation<T> {
11 > range: OffsetRange;
12 > annotation: T;
13 > }
14 >
15 > export interface IAnnotatedString<T> {
16 > /**
17 > * Set annotations for a specific line.
18 > * Annotations should be sorted and non-overlapping.
19 > */
20 > setAnnotations(annotations: AnnotationsUpdate<T>): void;
21 > /**
22 > * Return annotations intersecting with the given offset range.
23 > */
24 > getAnnotationsIntersecting(range: OffsetRange): IAnnotation<T>[];
25 > /**
26 > * Get all the annotations. Method is used for testing.
27 > */
28 > getAllAnnotations(): IAnnotation<T>[];
29 > /**
30 > * Apply a string edit to the annotated string.
31 > * @returns The annotations that were deleted (became empty) as a result of the edit.
32 > */
33 > applyEdit(edit: StringEdit): IAnnotation<T>[];
34 > /**
35 > * Clone the annotated string.
36 > */
37 > clone(): IAnnotatedString<T>;
38 > }
39 >
40 > export class AnnotatedString<T> implements IAnnotatedString<T> {
41 >
42 > /**
43 > * Annotations are non intersecting and contiguous in the array.
44 > */
45 > private _annotations: IAnnotation<T>[] = [];
46 >
47 > constructor(annotations: IAnnotation<T>[] = []) {
48 this._annotations = annotations;
49 }
51 > /**
52 > * Set annotations for a specific range.
53 > * Annotations should be sorted and non-overlapping.
54 > * If the annotation value is undefined, the annotation is removed.
55 > */
56 > public setAnnotations(annotations: AnnotationsUpdate<T>): void {
57 for (const annotation of annotations.annotations) {
58 const startIndex = this._getStartIndexOfIntersectingAnnotation(annotation.range.start);
65 }
66 }
68 > /**
69 > * Returns all annotations that intersect with the given offset range.
70 > */
71 > public getAnnotationsIntersecting(range: OffsetRange): IAnnotation<T>[] {
72 const startIndex = this._getStartIndexOfIntersectingAnnotation(range.start);
73 const endIndexExclusive = this._getEndIndexOfIntersectingAnnotation(range.endExclusive);
74 return this._annotations.slice(startIndex, endIndexExclusive);
75 }
77 > private _getStartIndexOfIntersectingAnnotation(offset: number): number {
78 // Find index to the left of the offset
79 const startIndexWhereToReplace = binarySearch2(this._annotations.length, (index) => {
98 return startIndex;
99 }
101 > private _getEndIndexOfIntersectingAnnotation(offset: number): number {
102 // Find index to the right of the offset
103 const endIndexWhereToReplace = binarySearch2(this._annotations.length, (index) => {
122 return endIndexExclusive;
123 }
125 > /**
126 > * Returns a copy of all annotations.
127 > */
128 > public getAllAnnotations(): IAnnotation<T>[] {
129 return this._annotations.slice();
130 }
132 > /**
133 > * Applies a string edit to the annotated string, updating annotation ranges accordingly.
134 > * @param edit The string edit to apply.
135 > * @returns The annotations that were deleted (became empty) as a result of the edit.
136 > */
137 > public applyEdit(edit: StringEdit): IAnnotation<T>[] {
138 const annotations = this._annotations.slice();
139
226 return deletedAnnotations;
227 }
229 > /**
230 > * Creates a shallow clone of this annotated string.
231 > */
232 > public clone(): IAnnotatedString<T> {
233 return new AnnotatedString<T>(this._annotations.slice());
234 }
235 > } annotations.ts
236 >
237 > export interface IAnnotationUpdate<T> {
238 > range: OffsetRange;
239 > annotation: T | undefined;
240 > }
241 >
242 > type DefinedValue = object | string | number | boolean;
243 >
244 > export type ISerializedAnnotation<TSerializedProperty extends DefinedValue> = {
245 > range: { start: number; endExclusive: number };
246 > annotation: TSerializedProperty | undefined;
247 > };
248 >
249 > export class AnnotationsUpdate<T> {
250 >
251 > public static create<T>(annotations: IAnnotationUpdate<T>[]): AnnotationsUpdate<T> {
252 return new AnnotationsUpdate(annotations);
253 }
255 > private _annotations: IAnnotationUpdate<T>[];
256 >
257 > private constructor(annotations: IAnnotationUpdate<T>[]) {
258 this._annotations = annotations;
259 }
261 > get annotations(): IAnnotationUpdate<T>[] {
262 return this._annotations;
263 }
265 > public rebase(edit: StringEdit): void {
266 const annotatedString = new AnnotatedString<T | undefined>(this._annotations);
267 annotatedString.applyEdit(edit);
268 this._annotations = annotatedString.getAllAnnotations();
269 }
271 > public serialize<TSerializedProperty extends DefinedValue>(serializingFunc: (annotation: T) => TSerializedProperty): ISerializedAnnotation<TSerializedProperty>[] {
272 return this._annotations.map(annotation => {
273 const range = { start: annotation.range.start, endExclusive: annotation.range.endExclusive };
278 });
279 }
281 > static deserialize<T, TSerializedProperty extends DefinedValue>(serializedAnnotations: ISerializedAnnotation<TSerializedProperty>[], deserializingFunc: (annotation: TSerializedProperty) => T): AnnotationsUpdate<T> {
282 const annotations: IAnnotationUpdate<T>[] = serializedAnnotations.map(serializedAnnotation => {
283 const range = new OffsetRange(serializedAnnotation.range.start, serializedAnnotation.range.endExclusive);
289 return new AnnotationsUpdate(annotations);
290 }
291 > } annotations.ts