diff --git a/lib/ruby-debug-ide/commands/expression_info.rb b/lib/ruby-debug-ide/commands/expression_info.rb index 3eccd52c..85addd92 100644 --- a/lib/ruby-debug-ide/commands/expression_info.rb +++ b/lib/ruby-debug-ide/commands/expression_info.rb @@ -12,8 +12,16 @@ def execute string_to_parse = Command.unescape_incoming(@match.post_match) + " \n \n\n" total_lines = string_to_parse.count("\n") + 1 - lexer = RubyLex.new - lexer.set_input(create_io_reader(string_to_parse)) + IRB.init_config(nil) unless IRB.conf && IRB.conf[:PROMPT] + irb_workspace = IRB::WorkSpace.new Object.new + irb_context = IRB::Context.new(nil, irb_workspace) + + lexer = RubyLex.instance_method(:initialize).arity == 1 ? + RubyLex.new(irb_context) : RubyLex.new + lexer.method(:set_input).arity == 1 ? + lexer.set_input(create_io_reader(string_to_parse)) : + lexer.set_input(create_io_reader(string_to_parse), context: irb_context) + last_statement = '' last_prompt = '' @@ -25,9 +33,9 @@ def execute last_indent = indent end - lexer.each_top_level_statement do |line, line_no| - last_statement = line - end + lexer.method(:each_top_level_statement).arity == 0 ? + lexer.each_top_level_statement { |line, line_no| last_statement = line } : + lexer.each_top_level_statement(irb_context) { |line, line_no| last_statement = line } incomplete = true if /\A\s*\Z/m =~ last_statement