don't index into line vector when getting line number from index; instead, just get how many previous-lines there are in the vector (if any) and add it to the line number of the current node. We do this because we are trying to get the line number of a particular index; accessing the line vector's contents (which are string indices) is not necessary nor helpful for that, but getting the relative line number is helpful for that

This commit is contained in:
2025-09-13 03:51:33 +01:00
parent db6fd56aca
commit 5c7ec252c2

View File

@@ -2666,8 +2666,7 @@ struct
val relativeIdx = findIdx - prevIdx val relativeIdx = findIdx - prevIdx
val relativeLine = binSearch (relativeIdx, lhd) val relativeLine = binSearch (relativeIdx, lhd)
in in
if relativeLine < 0 then prevLine if relativeLine < 0 then prevLine else prevLine + relativeLine
else Vector.sub (lhd, relativeLine) + prevLine
end end
else else
let val prevLine = curLine - Vector.length lhd let val prevLine = curLine - Vector.length lhd
@@ -2691,10 +2690,8 @@ struct
let let
val relativeIdx = findIdx - curIdx val relativeIdx = findIdx - curIdx
val relativeLine = binSearch (relativeIdx, lhd) val relativeLine = binSearch (relativeIdx, lhd)
val lineOffset =
if relativeLine < 0 then 0 else Vector.sub (lhd, relativeLine)
in in
curLine + lineOffset if relativeLine < 0 then curLine else curLine + relativeLine
end end
else else
let val nextLine = curLine + Vector.length lhd let val nextLine = curLine + Vector.length lhd