mirror of
https://gitea.invidious.io/iv-org/shard-backtracer.cr.git
synced 2024-08-15 00:53:13 +00:00
Add Backtrace::Line#context_hash
This commit is contained in:
parent
ece4858a29
commit
1b2e5fcc32
1 changed files with 21 additions and 0 deletions
|
@ -77,5 +77,26 @@ module Backtracer
|
|||
{pre_context, context_line, post_context}
|
||||
end
|
||||
end
|
||||
|
||||
def context_hash(context_lines : Int32? = nil) : Hash(Int32, String)?
|
||||
return unless context = self.context(context_lines)
|
||||
return unless lineno = self.number
|
||||
|
||||
pre_context, context_line, post_context = context
|
||||
|
||||
({} of Int32 => String).tap do |hash|
|
||||
pre_context.each_with_index do |code, index|
|
||||
line = (lineno - pre_context.size) + index
|
||||
hash[line] = code
|
||||
end
|
||||
|
||||
hash[lineno] = context_line
|
||||
|
||||
post_context.each_with_index do |code, index|
|
||||
line = lineno + (index + 1)
|
||||
hash[line] = code
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue