MCPcopy
hub / github.com/microsoft/pyright / convertOffsetToPosition

Function convertOffsetToPosition

server/src/common/positionUtils.ts:18–40  ·  view source on GitHub ↗
(offset: number, lines: TextRangeCollection<TextRange>)

Source from the content-addressed store, hash-verified

16
17// Translates a file offset into a line/column pair.
18export 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.
43export function convertOffsetsToRange(startOffset: number, endOffset: number,

Callers 1

convertOffsetsToRangeFunction · 0.85

Calls 2

getItemContainingMethod · 0.80
getItemAtMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…