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

restore support for IRB <= v1.13.0 #358

Merged
merged 2 commits into from
Dec 3, 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
16 changes: 12 additions & 4 deletions lib/iruby/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,29 @@ def initialize
@irb = IRB::Irb.new(@workspace)
@eval_path = @irb.context.irb_path
IRB.conf[:MAIN_CONTEXT] = @irb.context
@completor = IRB::RegexpCompletor.new
end

def eval_binding
@workspace.binding
end

def eval(code, store_history)
@irb.context.evaluate(@irb.build_statement(code), 0)
if Gem::Version.new(IRB::VERSION) < Gem::Version.new('1.13.0')
@irb.context.evaluate(code, 0)
else
@irb.context.evaluate(@irb.build_statement(code), 0)
end
@irb.context.last_value unless IRuby.silent_assignment && assignment_expression?(code)
end

def complete(code)
# preposing and postposing never used, so they are empty, pass only target as code
@completor.completion_candidates('', code, '', bind: @workspace.binding)
if defined? IRB::RegexpCompletor # IRB::VERSION >= 1.8.2
completor = IRB::RegexpCompletor.new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that an instance of IRB::RegexpCompletor is created each time. This seems inefficient, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, agree! Added e07b7eb

# preposing and postposing never used, so they are empty, pass only target as code
completor.completion_candidates('', code, '', bind: @workspace.binding)
else
IRB::InputCompletor::CompletionProc.call(code)
end
end

private
Expand Down
Loading