Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion lib/iruby/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ def eval(code, store_history)
end

class PlainBackend
attr_reader :eval_path
prepend History

def initialize
require 'bond'
Bond.start(debug: true)
@eval_path = '(iruby)'
end

def eval(code, store_history)
TOPLEVEL_BINDING.eval(code)
TOPLEVEL_BINDING.eval(code, @eval_path, 1)
end

def complete(code)
Expand All @@ -50,6 +52,7 @@ def complete(code)
end

class PryBackend
attr_reader :eval_path
prepend History

def initialize
Expand All @@ -58,10 +61,12 @@ def initialize
Pry.pager = false # Don't use the pager
Pry.print = proc {|output, value|} # No result printing
Pry.exception_handler = proc {|output, exception, _| }
@eval_path = Pry.eval_path
reset
end

def eval(code, store_history)
Pry.current_line = 1
@pry.last_result = nil
unless @pry.eval(code)
reset
Expand Down
3 changes: 2 additions & 1 deletion lib/iruby/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ def execute_request(msg)
end

def error_content(e)
backtrace = e.backtrace[0..e.backtrace.rindex{|line| line.start_with?(@backend.eval_path)}]
{ ename: e.class.to_s,
evalue: e.message,
traceback: ["#{RED}#{e.class}#{RESET}: #{e.message}", *e.backtrace] }
traceback: ["#{RED}#{e.class}#{RESET}: #{e.message}", *backtrace] }
end

def is_complete_request(msg)
Expand Down