-
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #393 from ko1/show_breakpoints
show valid break point lines
- Loading branch information
Showing
7 changed files
with
132 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'byebug/helpers/file' | ||
require 'byebug/setting' | ||
|
||
module Byebug | ||
# | ||
# Formats specific line ranges in a source file | ||
# | ||
class SourceFileFormatter | ||
include Helpers::FileHelper | ||
|
||
attr_reader :file, :annotator | ||
|
||
def initialize(file, annotator) | ||
@file = file | ||
@annotator = annotator | ||
end | ||
|
||
def lines(min, max) | ||
File.foreach(file).with_index.map do |line, lineno| | ||
next unless (min..max).cover?(lineno + 1) | ||
|
||
annotation = annotator.call(lineno + 1) | ||
|
||
format("%s %#{max.to_s.size}d: %s", annotation, lineno + 1, line) | ||
end | ||
end | ||
|
||
def lines_around(center) | ||
lines(*range_around(center)) | ||
end | ||
|
||
def range_around(center) | ||
range_from(center - size / 2) | ||
end | ||
|
||
def range_from(min) | ||
first = amend_initial(min) | ||
|
||
[first, first + size - 1] | ||
end | ||
|
||
def amend_initial(line) | ||
amend(line, max_initial_line) | ||
end | ||
|
||
def amend_final(line) | ||
amend(line, max_line) | ||
end | ||
|
||
def max_initial_line | ||
max_line - size + 1 | ||
end | ||
|
||
def max_line | ||
@max_line ||= n_lines(file) | ||
end | ||
|
||
def size | ||
[Setting[:listsize], max_line].min | ||
end | ||
|
||
def amend(line, ceiling) | ||
[ceiling, [1, line].max].min | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters