280
);
281
}
283
>
/**
284
>
* Return the end position (which will be after or equal to the start position)
285
>
*/
286
>
public getEndPosition(): Position {
287
return Range.getEndPosition(this);
288
}
290
>
/**
291
>
* Return the end position (which will be after or equal to the start position)
292
>
*/
293
>
public static getEndPosition(range: IRange): Position {
294
return new Position(range.endLineNumber, range.endColumn);
295
}
297
>
/**
298
>
* Return the start position (which will be before or equal to the end position)
299
>
*/
300
>
public getStartPosition(): Position {
301
return Range.getStartPosition(this);
302
}
304
>
/**
305
>
* Return the start position (which will be before or equal to the end position)
306
>
*/
307
>
public static getStartPosition(range: IRange): Position {
308
return new Position(range.startLineNumber, range.startColumn);
309
}
311
>
/**
312
>
* Transform to a user presentable string representation.
313
>
*/
314
>
public toString(): string {
315
return '[' + this.startLineNumber + ',' + this.startColumn + ' -> ' + this.endLineNumber + ',' + this.endColumn + ']';
316
}
318
>
/**
319
>
* Create a new range using this range's start position, and using endLineNumber and endColumn as the end position.
320
>
*/
321
>
public setEndPosition(endLineNumber: number, endColumn: number): Range {
322
return new Range(this.startLineNumber, this.startColumn, endLineNumber, endColumn);
323
}
325
>
/**
326
>
* Create a new range using this range's end position, and using startLineNumber and startColumn as the start position.
327
>
*/
328
>
public setStartPosition(startLineNumber: number, startColumn: number): Range {
329
return new Range(startLineNumber, startColumn, this.endLineNumber, this.endColumn);
330
}
332
>
/**
333
>
* Create a new empty range using this range's start position.
334
>
*/
335
>
public collapseToStart(): Range {
336
return Range.collapseToStart(this);
337
}
339
>
/**
340
>
* Create a new empty range using this range's start position.
341
>
*/
342
>
public static collapseToStart(range: IRange): Range {
343
return new Range(range.startLineNumber, range.startColumn, range.startLineNumber, range.startColumn);
344
}
346
>
/**
347
>
* Create a new empty range using this range's end position.
348
>
*/
349
>
public collapseToEnd(): Range {
350
return Range.collapseToEnd(this);
351
}
353
>
/**
354
>
* Create a new empty range using this range's end position.
355
>
*/
356
>
public static collapseToEnd(range: IRange): Range {
357
return new Range(range.endLineNumber, range.endColumn, range.endLineNumber, range.endColumn);
358
}
360
>
/**
361
>
* Moves the range by the given amount of lines.
362
>
*/
363
>
public delta(lineCount: number): Range {
364
return new Range(this.startLineNumber + lineCount, this.startColumn, this.endLineNumber + lineCount, this.endColumn);
365
}
367
>
/**
368
>
* Test if this range starts and ends on the same line.
369
>
*/
370
>
public isSingleLine(): boolean {
371
return this.startLineNumber === this.endLineNumber;
372
}
374
>
// ---
375
>
376
>
public static fromPositions(start: IPosition, end: IPosition = start): Range {
377
return new Range(start.lineNumber, start.column, end.lineNumber, end.column);
378
}
380
>
/**
381
>
* Create a `Range` from an `IRange`.
382
>
*/
383
>
public static lift(range: undefined | null): null;
384
>
public static lift(range: IRange): Range;
385
>
public static lift(range: IRange | undefined | null): Range | null;
386
>
public static lift(range: IRange | undefined | null): Range | null {
387
if (!range) {
388
return null;