Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Prism::Source#find_line
find_line(byte_offset)
lib/prism/parse_result.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/prism/parse_result.rb, line 63
def find_line(byte_offset)
left = 0
right = offsets.length - 1
while left <= right
mid = left + (right - left) / 2
return mid if offsets[mid] == byte_offset
if offsets[mid] < byte_offset
left = mid + 1
else
right = mid - 1
end
end
left - 1
end
Binary search through the offsets to find the line number for the given byte offset.