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
}
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
}
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)