Skip to content

Commit 77265ef

Browse files
authored
Restore IRB::InputCompletor for compatibility (#730)
1 parent 47693a2 commit 77265ef

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/irb/completion.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,20 @@ def select_message(receiver, message, candidates, sep = ".")
415415
end
416416
end
417417
end
418+
419+
module InputCompletor
420+
class << self
421+
private def regexp_completor
422+
@regexp_completor ||= RegexpCompletor.new
423+
end
424+
425+
def retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding, doc_namespace: false)
426+
regexp_completor.retrieve_completion_data(input, bind: bind, doc_namespace: doc_namespace)
427+
end
428+
end
429+
CompletionProc = ->(target, preposing = nil, postposing = nil) {
430+
regexp_completor.completion_candidates(preposing, target, postposing, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding)
431+
}
432+
end
433+
deprecate_constant :InputCompletor
418434
end

test/irb/test_completion.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,29 @@ def instance_variables; end
265265
assert_include(doc_namespace("private_hoge", bind), "private_hoge")
266266
end
267267
end
268+
269+
class DeprecatedInputCompletorTest < TestCase
270+
def setup
271+
@verbose, $VERBOSE = $VERBOSE, nil
272+
IRB.init_config(nil)
273+
IRB.conf[:MAIN_CONTEXT] = IRB::Context.new(IRB::WorkSpace.new(binding))
274+
end
275+
276+
def teardown
277+
$VERBOSE = @verbose
278+
end
279+
280+
def test_completion_proc
281+
assert_include(IRB::InputCompletor::CompletionProc.call('1.ab'), '1.abs')
282+
assert_include(IRB::InputCompletor::CompletionProc.call('1.ab', '', ''), '1.abs')
283+
end
284+
285+
def test_retrieve_completion_data
286+
assert_include(IRB::InputCompletor.retrieve_completion_data('1.ab'), '1.abs')
287+
assert_equal(IRB::InputCompletor.retrieve_completion_data('1.abs', doc_namespace: true), 'Integer.abs')
288+
bind = eval('a = 1; binding')
289+
assert_include(IRB::InputCompletor.retrieve_completion_data('a.ab', bind: bind), 'a.abs')
290+
assert_equal(IRB::InputCompletor.retrieve_completion_data('a.abs', bind: bind, doc_namespace: true), 'Integer.abs')
291+
end
292+
end
268293
end

0 commit comments

Comments
 (0)