1
>
/*---------------------------------------------------------------------------------------------
lineRange.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 { BugIndicatingError } from '../../../../base/common/errors.js';
7
>
import { OffsetRange } from './offsetRange.js';
8
>
import { IRange, Range } from '../range.js';
9
>
import { findFirstIdxMonotonousOrArrLen, findLastIdxMonotonous, findLastMonotonous } from '../../../../base/common/arraysFind.js';
10
>
import { Comparator, compareBy, numberComparator } from '../../../../base/common/arrays.js';
11
>
12
>
/**
13
>
* A range of lines (1-based).
14
>
*/
15
>
export class LineRange {
16
>
public static ofLength(startLineNumber: number, length: number): LineRange {
17
return new LineRange(startLineNumber, startLineNumber + length);
18
}
20
>
public static fromRange(range: IRange): LineRange {
21
return new LineRange(range.startLineNumber, range.endLineNumber);
22
}
24
>
public static fromRangeInclusive(range: IRange): LineRange {
25
return new LineRange(range.startLineNumber, range.endLineNumber + 1);
26
}
28
>
public static readonly compareByStart: Comparator<LineRange> = compareBy(l => l.startLineNumber, numberComparator);
29
>
30
>
public static subtract(a: LineRange, b: LineRange | undefined): LineRange[] {
31
if (!b) {
32
return [a];