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

Powerup show_source by enabling RubyVM.keep_script_lines #862

Merged
merged 6 commits into from
Feb 12, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Memoize irb_path existence to reduce file existence check calculating…
… eval_path
tompng committed Feb 12, 2024
commit 125693c8510ede3dc0bf4224c45e595f2716ba67
11 changes: 8 additions & 3 deletions lib/irb/context.rb
Original file line number Diff line number Diff line change
@@ -555,9 +555,6 @@ def evaluate(line, line_no) # :nodoc:
IRB.set_measure_callback
end

# We need to use differente path to distinguish source_location of method defined in the actual file and method defined in irb session.
eval_path = File.exist?(irb_path) ? "#{irb_path}(#{IRB.conf[:IRB_NAME]})" : irb_path

if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
last_proc = proc do
result = @workspace.evaluate(line, eval_path, line_no)
@@ -577,6 +574,14 @@ def evaluate(line, line_no) # :nodoc:
set_last_value(result)
end

private def eval_path
# We need to use differente path to distinguish source_location of method defined in the actual file and method defined in irb session.
if !defined?(@irb_path_existence) || @irb_path_existence[0] != irb_path
@irb_path_existence = [irb_path, File.exist?(irb_path)]
end
@irb_path_existence[1] ? "#{irb_path}(#{IRB.conf[:IRB_NAME]})" : irb_path
end

def inspect_last_value # :nodoc:
@inspect_method.inspect_value(@last_value)
end
9 changes: 9 additions & 0 deletions test/irb/test_context.rb
Original file line number Diff line number Diff line change
@@ -666,6 +666,15 @@ def test_lineno
], out)
end

def test_eval_path
@context.irb_path = __FILE__
assert_equal("#{__FILE__}(irb)", @context.send(:eval_path))
@context.irb_path = 'file/does/not/exist'
assert_equal('file/does/not/exist', @context.send(:eval_path))
@context.irb_path = "#{__FILE__}(irb)"
assert_equal("#{__FILE__}(irb)", @context.send(:eval_path))
end

def test_build_completor
verbose, $VERBOSE = $VERBOSE, nil
original_completor = IRB.conf[:COMPLETOR]