lib/elastic_apm/stacktrace/frame.rb in elastic-apm-0.3.0 vs lib/elastic_apm/stacktrace/frame.rb in elastic-apm-0.4.0
- old
+ new
@@ -18,20 +18,23 @@
:lineno,
:module,
:colno
)
+ # rubocop:disable Metrics/AbcSize
def build_context(context_line_count)
- return unless abs_path
+ return unless abs_path && context_line_count > 0
- from = (lineno - context_line_count - 1)
- to = (lineno + context_line_count)
+ padding = (context_line_count - 1) / 2
+ from = lineno - padding - 1
+ to = lineno + padding - 1
file_lines = read_lines(abs_path, from..to)
- self.context_line = file_lines[context_line_count]
- self.pre_context = file_lines.first(context_line_count)
- self.post_context = file_lines.last(context_line_count)
+ self.context_line = file_lines[padding]
+ self.pre_context = file_lines.first(padding)
+ self.post_context = file_lines.last(padding)
end
+ # rubocop:enable Metrics/AbcSize
private
def read_lines(path, range)
if (cached = LineCache.get(path, range))