MCPcopy Create free account
hub / github.com/arktypeio/arktype / lineAndColumnOf

Method lineAndColumnOf

ark/aot/module.ts:99–118  ·  view source on GitHub ↗
(offset: number)

Source from the content-addressed store, hash-verified

97 }
98
99 lineAndColumnOf(offset: number): [line: number, column: number] {
100 this.lineStarts ??= computeLineStarts(this.source)
101 let low = 0
102 let high = this.lineStarts.length - 1
103 while (low < high) {
104 const mid = (low + high + 1) >> 1
105 if (this.lineStarts[mid] <= offset) low = mid
106 else high = mid - 1
107 }
108 const column = offset - this.lineStarts[low]
109 // the last segment starting at or before the column, sorted by column
110 let mapped: SourceMapSegment | undefined
111 for (const segment of this.mappings?.[low] ?? []) {
112 if (segment[0] > column) break
113 if (segment.length > 1) mapped = segment
114 }
115 return mapped ?
116 [mapped[2]! + 1, mapped[3]! + column - mapped[0] + 1]
117 : [low + 1, column + 1]
118 }
119
120 positionOf(span: Span): string {
121 const [line, column] = this.lineAndColumnOf(span.start)

Callers 6

constructorMethod · 0.95
positionOfMethod · 0.95
isDropNarrowSuppressedFunction · 0.80
siteOfMethod · 0.80
diagnosticMethod · 0.80

Calls 1

computeLineStartsFunction · 0.85

Tested by

no test coverage detected