summaryrefslogtreecommitdiff
path: root/lib/irb/context.rb
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2024-02-13 03:38:27 +0900
committergit <[email protected]>2024-02-12 18:38:30 +0000
commit7af97dc71fd6790a3f4ffe47dcc5720b675f6b6b (patch)
tree746868021ac678da2ab27261d88794a1daf9e2d2 /lib/irb/context.rb
parente878bbd641f255b5d8f9e99b84ff8082a5b7fdaf (diff)
[ruby/irb] Powerup show_source by enabling RubyVM.keep_script_lines
(https://github.com/ruby/irb/pull/862) * Powerup show_source by enabling RubyVM.keep_script_lines * Add file_content field to avoid reading file twice while show_source * Change path passed to eval, don't change irb_path. * Encapsulate source coloring logic and binary file check insode class Source * Add edit command testcase when irb_path does not exist * Memoize irb_path existence to reduce file existence check calculating eval_path https://github.com/ruby/irb/commit/239683a937
Diffstat (limited to 'lib/irb/context.rb')
-rw-r--r--lib/irb/context.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index e30125f46b..814a8bd4ad 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -557,7 +557,7 @@ module IRB
if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
last_proc = proc do
- result = @workspace.evaluate(line, irb_path, line_no)
+ result = @workspace.evaluate(line, eval_path, line_no)
end
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) do |chain, item|
_name, callback, arg = item
@@ -568,12 +568,20 @@ module IRB
end
end.call
else
- result = @workspace.evaluate(line, irb_path, line_no)
+ result = @workspace.evaluate(line, eval_path, line_no)
end
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