A range represents an ordered pair of two positions. It is guaranteed that {@link Range.start start}.isBeforeOrEqual({@link Range.end end})

Range objects are immutable. Use the {@link Range.with with}, {@link Range.intersection intersection}, or {@link Range.union union} methods to derive new ranges from an existing range.

Constructor

new(start:Position, end:Position)

new(startLine:Int, startCharacter:Int, endLine:Int, endCharacter:Int)

Create a new range from two positions. If start is not before or equal to end, the values will be swapped.

Parameters:

start

A position.

end

A position.

Variables

read onlyend:Position

The end position. It is after or equal to {@link Range.start start}.

isEmpty:Bool

true if start and end are equal.

isSingleLine:Bool

true if start.line and end.line are equal.

read onlystart:Position

The start position. It is before or equal to {@link Range.end end}.

Methods

contains(positionOrRange:EitherType<Position, Range>):Bool

Check if a position or a range is contained in this range.

Parameters:

positionOrRange

A position or a range.

Returns:

true if the position or range is inside or equal to this range.

intersection(range:Range):Null<Range>

Intersect range with this range and returns a new range or undefined if the ranges have no overlap.

Parameters:

range

A range.

Returns:

A range of the greater start and smaller end positions. Will return undefined when there is no overlap.

isEqual(other:Range):Bool

Check if other equals this range.

@link Position.isEqual equal} to start and end of this range.

Parameters:

other

A range.

Returns:

true when start and end are {

union(other:Range):Range

Compute the union of other with this range.

Parameters:

other

A range.

Returns:

A range of smaller start position and the greater end position.

with(?start:Position, ?end:Position):Range

with(change:{start:Null<Position>, end:Null<Position>}):Range

Derived a new range from this range.

@link Range.start current start}. @link Range.end current end}.

Parameters:

start

A position that should be used as start. The default value is the {

end

A position that should be used as end. The default value is the {

Returns:

A range derived from this range with the given start and end position. If start and end are not different this range will be returned.