@@ -12,32 +12,27 @@ export class Range {
12
12
readonly end : Position ;
13
13
14
14
/**
15
- * Create a new range from two positions. If `start` is not
16
- * before or equal to `end`, the values will be swapped .
15
+ * Create a new range from two positions.
16
+ * The earlier of `p1` and `p2` will be used as the start position .
17
17
*
18
- * @param start A position.
19
- * @param end A position.
18
+ * @param p1 A position.
19
+ * @param p2 A position.
20
20
*/
21
- constructor ( start : Position , end : Position ) ;
21
+ constructor ( p1 : Position , p2 : Position ) ;
22
22
23
23
/**
24
- * Create a new range from number coordinates. It is a shorter equivalent of
25
- * using `new Range(new Position(startLine, startCharacter ), new Position(endLine, endCharacter ))`
24
+ * Create a new range from number coordinates.
25
+ * It is equivalent to `new Range(new Position(line1, char1 ), new Position(line2, char2 ))`
26
26
*
27
- * @param startLine A zero-based line value.
28
- * @param startCharacter A zero-based character value.
29
- * @param endLine A zero-based line value.
30
- * @param endCharacter A zero-based character value.
27
+ * @param line1 A zero-based line value.
28
+ * @param char1 A zero-based character value.
29
+ * @param line2 A zero-based line value.
30
+ * @param char2 A zero-based character value.
31
31
*/
32
- constructor (
33
- startLine : number ,
34
- startCharacter : number ,
35
- endLine : number ,
36
- endCharacter : number ,
37
- ) ;
32
+ constructor ( line1 : number , char1 : number , line2 : number , char2 : number ) ;
38
33
39
34
constructor ( ...args : any [ ] ) {
40
- const [ start , end ] : [ Position , Position ] = ( ( ) => {
35
+ const [ p1 , p2 ] : [ Position , Position ] = ( ( ) => {
41
36
// Arguments are two positions
42
37
if ( args . length === 2 ) {
43
38
return args as [ Position , Position ] ;
@@ -48,12 +43,12 @@ export class Range {
48
43
} ) ( ) ;
49
44
50
45
// Ranges are always non-reversed
51
- if ( start . isBefore ( end ) ) {
52
- this . start = start ;
53
- this . end = end ;
46
+ if ( p1 . isBefore ( p2 ) ) {
47
+ this . start = p1 ;
48
+ this . end = p2 ;
54
49
} else {
55
- this . start = end ;
56
- this . end = start ;
50
+ this . start = p2 ;
51
+ this . end = p1 ;
57
52
}
58
53
}
59
54
@@ -98,8 +93,9 @@ export class Range {
98
93
}
99
94
100
95
/**
101
- * Intersect `range` with this range and returns a new range or `undefined`
102
- * if the ranges have no overlap.
96
+ * Intersect `range` with this range and returns a new range.
97
+ * If the ranges are adjacent but non-overlapping, the resulting range is empty.
98
+ * If the ranges have no overlap and are not adjacent, it returns `undefined`.
103
99
*
104
100
* @param other A range.
105
101
* @return A range of the greater start and smaller end positions. Will
@@ -125,12 +121,12 @@ export class Range {
125
121
}
126
122
127
123
/**
128
- * Derived a new range from this range.
124
+ * Derive a new range from this range.
125
+ * If the resulting range has end before start, they are swapped.
129
126
*
130
127
* @param start A position that should be used as start. The default value is the {@link Range.start current start}.
131
128
* @param end A position that should be used as end. The default value is the {@link Range.end current end}.
132
129
* @return A range derived from this range with the given start and end position.
133
- * If start and end are not different `this` range will be returned.
134
130
*/
135
131
public with ( start ?: Position , end ?: Position ) : Range {
136
132
return new Range ( start ?? this . start , end ?? this . end ) ;
0 commit comments