Return the offset between the error lineno and the source lineno. Searches
in reverse from the backtrace lineno so we have a better chance of finding
the correct line
The compiled template is likely to be longer than the source. Use the
difference between the compiled and source sizes to determine the earliest
line that could contain the highlight.
# File actionview/lib/action_view/template/handlers/erb.rb, line 119
def find_lineno_offset(compiled, source_lines, highlight, error_lineno)
first_index = error_lineno - 1 - compiled.size + source_lines.size
first_index = 0 if first_index < 0
last_index = error_lineno - 1
last_index = source_lines.size - 1 if last_index >= source_lines.size
last_index.downto(first_index) do |line_index|
next unless source_lines[line_index].include?(highlight)
return error_lineno - 1 - line_index
end
raise LocationParsingError, "Couldn't find code snippet"
end