(offset: number, lines: TextRangeCollection<TextRange>)
| 16 | |
| 17 | // Translates a file offset into a line/column pair. |
| 18 | export function convertOffsetToPosition(offset: number, lines: TextRangeCollection<TextRange>): DiagnosticTextPosition { |
| 19 | // Handle the case where the file is empty. |
| 20 | if (lines.end === 0) { |
| 21 | return { |
| 22 | line: 0, |
| 23 | column: 0 |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | // Handle the case where we're pointing to the last line of the file. |
| 28 | if (offset >= lines.end) { |
| 29 | offset = lines.end - 1; |
| 30 | } |
| 31 | |
| 32 | let itemIndex = lines.getItemContaining(offset); |
| 33 | assert(itemIndex >= 0 && itemIndex <= lines.length); |
| 34 | let lineRange = lines.getItemAt(itemIndex); |
| 35 | assert(lineRange !== undefined); |
| 36 | return { |
| 37 | line: itemIndex, |
| 38 | column: offset - lineRange.start |
| 39 | }; |
| 40 | } |
| 41 | |
| 42 | // Translates a start/end file offset into a pair of line/column positions. |
| 43 | export function convertOffsetsToRange(startOffset: number, endOffset: number, |
no test coverage detected
searching dependent graphs…