Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ISeq#path with ISeq#absolute_path #544

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/debug/source_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def get iseq
if lines = iseq.script_lines&.map(&:chomp)
lines
else
nil
if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
File.readlines(path, chomp: true)
else
nil
end
end
end

Expand All @@ -50,7 +54,7 @@ def initialize
end

def add iseq, src
if (path = iseq.absolute_path) && File.exist?(path)
if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
add_path path
elsif src
add_iseq iseq, src
Expand Down Expand Up @@ -78,9 +82,8 @@ def add iseq, src
end

private def add_path path
src = File.read(path)
src = src.gsub("\r\n", "\n") # CRLF -> LF
@files[path] = SrcInfo.new(src.lines)
src_lines = File.readlines(path, chomp: true)
@files[path] = SrcInfo.new(src_lines)
rescue SystemCallError
end

Expand All @@ -89,7 +92,7 @@ def add iseq, src

if iseq.instance_variable_defined?(:@debugger_si)
iseq.instance_variable_get(:@debugger_si)
elsif @files.has_key?(path = iseq.absolute_path)
elsif @files.has_key?(path = (iseq.absolute_path || iseq.path))
@files[path]
elsif path
add_path(path)
Expand All @@ -105,7 +108,7 @@ def get iseq
def get_colored iseq
if si = get_si(iseq)
si.colored || begin
si.colored = colorize_code(si.src.join).lines
si.colored = colorize_code(si.src.join("\n")).lines
end
end
end
Expand Down