length.ts ×22

Frontier kind: Code frontier

unlabeled · c_e38162937390

879 tests · 5791 LOC · 32 files · introduces 0 tests · 89 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
22 ranges89 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
906 ranges5791 lines · 32 files · Browse complete extent
All tests (intent)
879 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: 89 introduced LOC across 22 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/length.ts 89 introduced LOC · 22 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- length.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 { splitLines } from '../../../../../base/common/strings.js';
7 > import { Position } from '../../../core/position.js';
8 > import { Range } from '../../../core/range.js';
9 > import { TextLength } from '../../../core/text/textLength.js';
10 >
11 > /**
12 > * The end must be greater than or equal to the start.
13 > */
14 > export function lengthDiff(startLineCount: number, startColumnCount: number, endLineCount: number, endColumnCount: number): Length {
15 return (startLineCount !== endLineCount)
16 ? toLength(endLineCount - startLineCount, endColumnCount)
17 : toLength(0, endColumnCount - startColumnCount);
18 }
19 > length.ts
20 > /**
21 > * Represents a non-negative length in terms of line and column count.
22 > * Does not allocate.
23 > */
24 > export type Length = { _brand: 'Length' };
25 >
26 > // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
27 > export const lengthZero = 0 as any as Length;
28 >
29 > export function lengthIsZero(length: Length): boolean {
30 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
31 return length as any as number === 0;
32 }
33 > length.ts
34 > /*
35 > * We have 52 bits available in a JS number.
36 > * We use the upper 26 bits to store the line and the lower 26 bits to store the column.
37 > */
38 > ///*
39 > const factor = 2 ** 26;
40 > /*/
41 > const factor = 1000000;
42 > // */
43 >
44 > export function toLength(lineCount: number, columnCount: number): Length {
45 // llllllllllllllllllllllllllcccccccccccccccccccccccccc (52 bits)
46 // line count (26 bits) column count (26 bits)
52 return (lineCount * factor + columnCount) as any as Length;
53 }
54 > length.ts
55 > export function lengthToObj(length: Length): TextLength {
56 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
57 const l = length as any as number;
60 return new TextLength(lineCount, columnCount);
61 }
62 > length.ts
63 > export function lengthGetLineCount(length: Length): number {
64 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
65 return Math.floor(length as any as number / factor);
66 }
67 > length.ts
68 > /**
69 > * Returns the amount of columns of the given length, assuming that it does not span any line.
70 > */
71 > export function lengthGetColumnCountIfZeroLineCount(length: Length): number {
72 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
73 return length as any as number;
74 }
75 > length.ts
76 >
77 > // [10 lines, 5 cols] + [ 0 lines, 3 cols] = [10 lines, 8 cols]
78 > // [10 lines, 5 cols] + [20 lines, 3 cols] = [30 lines, 3 cols]
79 > export function lengthAdd(length1: Length, length2: Length): Length;
80 > // eslint-disable-next-line @typescript-eslint/no-explicit-any
81 > export function lengthAdd(l1: any, l2: any): Length {
82 let r = l1 + l2;
83 if (l2 >= factor) { r = r - (l1 % factor); }
84 return r;
85 }
86 > length.ts
87 > export function sumLengths<T>(items: readonly T[], lengthFn: (item: T) => Length): Length {
88 return items.reduce((a, b) => lengthAdd(a, lengthFn(b)), lengthZero);
89 }
90 > length.ts
91 > export function lengthEquals(length1: Length, length2: Length): boolean {
92 return length1 === length2;
93 }
94 > length.ts
95 > /**
96 > * Returns a non negative length `result` such that `lengthAdd(length1, result) = length2`, or zero if such length does not exist.
97 > */
98 > export function lengthDiffNonNegative(length1: Length, length2: Length): Length {
99 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
100 const l1 = length1 as any as number;
121 }
122 }
123 > length.ts
124 > export function lengthLessThan(length1: Length, length2: Length): boolean {
125 // First, compare line counts, then column counts.
126 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
127 return (length1 as any as number) < (length2 as any as number);
128 }
129 > length.ts
130 > export function lengthLessThanEqual(length1: Length, length2: Length): boolean {
131 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
132 return (length1 as any as number) <= (length2 as any as number);
133 }
134 > length.ts
135 > export function lengthGreaterThanEqual(length1: Length, length2: Length): boolean {
136 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
137 return (length1 as any as number) >= (length2 as any as number);
138 }
139 > length.ts
140 > export function lengthToPosition(length: Length): Position {
141 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
142 const l = length as any as number;
145 return new Position(lineCount + 1, colCount + 1);
146 }
147 > length.ts
148 > export function positionToLength(position: Position): Length {
149 return toLength(position.lineNumber - 1, position.column - 1);
150 }
151 > length.ts
152 > export function lengthsToRange(lengthStart: Length, lengthEnd: Length): Range {
153 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
154 const l = lengthStart as any as number;
163 return new Range(lineCount + 1, colCount + 1, lineCount2 + 1, colCount2 + 1);
164 }
165 > length.ts
166 > export function lengthOfRange(range: Range): TextLength {
167 if (range.startLineNumber === range.endLineNumber) {
168 return new TextLength(0, range.endColumn - range.startColumn);
171 }
172 }
173 > length.ts
174 > export function lengthCompare(length1: Length, length2: Length): number {
175 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
176 const l1 = length1 as any as number;
179 return l1 - l2;
180 }
181 > length.ts
182 > export function lengthOfString(str: string): Length {
183 const lines = splitLines(str);
184 return toLength(lines.length - 1, lines[lines.length - 1].length);
185 }
186 > length.ts
187 > export function lengthOfStringObj(str: string): TextLength {
188 const lines = splitLines(str);
189 return new TextLength(lines.length - 1, lines[lines.length - 1].length);
190 }
191 > length.ts
192 > /**
193 > * Computes a numeric hash of the given length.
194 > */
195 > export function lengthHash(length: Length): number {
196 // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
197 return length as any;
198 }
199 > length.ts
200 > export function lengthMax(length1: Length, length2: Length): Length {
201 return length1 > length2 ? length1 : length2;
202 }