Skip to content

Commit

Permalink
Restore IRB::InputCompletor for compatibility (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng authored Oct 14, 2023
1 parent 47693a2 commit 77265ef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,20 @@ def select_message(receiver, message, candidates, sep = ".")
end
end
end

module InputCompletor
class << self
private def regexp_completor
@regexp_completor ||= RegexpCompletor.new
end

def retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding, doc_namespace: false)
regexp_completor.retrieve_completion_data(input, bind: bind, doc_namespace: doc_namespace)
end
end
CompletionProc = ->(target, preposing = nil, postposing = nil) {
regexp_completor.completion_candidates(preposing, target, postposing, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding)
}
end
deprecate_constant :InputCompletor
end
25 changes: 25 additions & 0 deletions test/irb/test_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,29 @@ def instance_variables; end
assert_include(doc_namespace("private_hoge", bind), "private_hoge")
end
end

class DeprecatedInputCompletorTest < TestCase
def setup
@verbose, $VERBOSE = $VERBOSE, nil
IRB.init_config(nil)
IRB.conf[:MAIN_CONTEXT] = IRB::Context.new(IRB::WorkSpace.new(binding))
end

def teardown
$VERBOSE = @verbose
end

def test_completion_proc
assert_include(IRB::InputCompletor::CompletionProc.call('1.ab'), '1.abs')
assert_include(IRB::InputCompletor::CompletionProc.call('1.ab', '', ''), '1.abs')
end

def test_retrieve_completion_data
assert_include(IRB::InputCompletor.retrieve_completion_data('1.ab'), '1.abs')
assert_equal(IRB::InputCompletor.retrieve_completion_data('1.abs', doc_namespace: true), 'Integer.abs')
bind = eval('a = 1; binding')
assert_include(IRB::InputCompletor.retrieve_completion_data('a.ab', bind: bind), 'a.abs')
assert_equal(IRB::InputCompletor.retrieve_completion_data('a.abs', bind: bind, doc_namespace: true), 'Integer.abs')
end
end
end

0 comments on commit 77265ef

Please sign in to comment.