File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
apps/oxlint/src-js/plugins Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,13 @@ export function getLineColumnFromOffset(offset: number): LineColumn {
171171function populateLineColumn ( offset : number , out : LineColumn ) : void {
172172 debugAssertLinesIsInitialized ( ) ;
173173
174- // Binary search `lineStartIndices` for the line containing `offset`
174+ // Find first line that starts *after* `offset`, via binary search of `lineStartIndices`.
175+ // `lineStartIndices` is sorted and `lineStartIndices[0]` is always 0.
176+ //
177+ // After the loop, `low` is the index of the first line whose start is *past* `offset`.
178+ // This is also the 1-indexed line number of the line containing `offset`.
179+ // e.g. if `offset` is on the 3rd line, `low` = 3, and `lineStartIndices[2]` is that line's start.
180+ // `do...while` is safe because `lineStartIndices` always has at least one entry, so `low < high` at start of loop.
175181 let low = 0 ,
176182 high = lineStartIndices . length ,
177183 mid : number ;
@@ -184,8 +190,8 @@ function populateLineColumn(offset: number, out: LineColumn): void {
184190 }
185191 } while ( low < high ) ;
186192
187- out . line = low ;
188- out . column = offset - lineStartIndices [ low - 1 ] ;
193+ out . line = low ; // 1-indexed line number
194+ out . column = offset - lineStartIndices [ low - 1 ] ; // Offset from start of the line
189195}
190196
191197/**
You can’t perform that action at this time.
0 commit comments