1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

input becomes primary argument in #initialize.

with `_pry_` as an optional second. in the repl the second argument will
always be met but to avoid needing a pry instance around to use Pry::InputCompleter,
it uses the first argument(`input`) when implementing auto completion, and
'pry' can be used if its around/available.
This commit is contained in:
robert 2014-04-03 02:16:24 +02:00 committed by Ryan Fitzgerald
parent a550491fca
commit 3fd66b6403
3 changed files with 11 additions and 15 deletions

View file

@ -1,7 +1,6 @@
# taken from irb
# Implements tab completion for Readline in Pry
class Pry::InputCompleter
NUMERIC_REGEXP = /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
ARRAY_REGEXP = /^([^\]]*\])\.([^.]*)$/
SYMBOL_REGEXP = /^(:[^:.]*)$/
@ -42,13 +41,9 @@ class Pry::InputCompleter
WORD_ESCAPE_STR = " \t\n\"\\'`><=;|&{("
def initialize(pry = nil)
if pry
@pry = pry
@input = pry.input
else
@input = Readline
end
def initialize(input, pry = nil)
@pry = pry if pry
@input = input
@input.basic_word_break_characters = WORD_ESCAPE_STR if @input.respond_to?(:basic_word_break_characters=)
@input.completion_append_character = nil if @input.respond_to?(:completion_append_character=)
end

View file

@ -127,7 +127,8 @@ class Pry
def complete(input)
return EMPTY_COMPLETIONS unless config.completer
Pry.critical_section do
completer = config.completer.new(self)
completer = config.completer.new(input, self)
# todo: `input` argument isn't needed.
completer.call input, target: current_binding, custom_completions: custom_completions.call.push(*sticky_locals.keys)
end
end

View file

@ -4,7 +4,7 @@ require "pry/input_completer"
def completer_test(bind, pry=nil, assert_flag=true)
test = proc {|symbol|
Pry::InputCompleter.new(pry).call(symbol[0..-2], :target => Pry.binding_for(bind)).include?(symbol).should == assert_flag}
Pry::InputCompleter.new(pry || Readline, pry).call(symbol[0..-2], :target => Pry.binding_for(bind)).include?(symbol).should == assert_flag}
return proc {|*symbols| symbols.each(&test) }
end
@ -30,12 +30,12 @@ describe Pry::InputCompleter do
# another jruby hack :((
if !Pry::Helpers::BaseHelpers.jruby?
it "should not crash if there's a Module that has a symbolic name." do
lambda{ Pry::InputCompleter.new.call "a.to_s.", :target => Pry.binding_for(Object.new) }.should.not.raise Exception
lambda{ Pry::InputCompleter.new(Readline).call "a.to_s.", :target => Pry.binding_for(Object.new) }.should.not.raise Exception
end
end
it 'should take parenthesis and other characters into account for symbols' do
lambda { Pry::InputCompleter.new.call(":class)", :target => Pry.binding_for(Object.new)) }.should.not.raise(RegexpError)
lambda { Pry::InputCompleter.new(Readline).call(":class)", :target => Pry.binding_for(Object.new)) }.should.not.raise(RegexpError)
end
it 'should complete instance variables' do
@ -114,7 +114,7 @@ describe Pry::InputCompleter do
completer_test(binding).call('o.foo')
# trailing slash
Pry::InputCompleter.new.call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/').should == true
Pry::InputCompleter.new(Readline).call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/').should == true
end
it 'should complete for arbitrary scopes' do
@ -185,7 +185,7 @@ describe Pry::InputCompleter do
completer_test(binding).call('o.foo')
# trailing slash
Pry::InputCompleter.new.call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/').should == true
Pry::InputCompleter.new(Readline).call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/').should == true
end
it 'should complete for arbitrary scopes' do
@ -209,6 +209,6 @@ describe Pry::InputCompleter do
it 'should not return nil in its output' do
pry = Pry.new
Pry::InputCompleter.new(pry).call("pry.", :target => binding).should.not.include nil
Pry::InputCompleter.new(Readline, pry).call("pry.", :target => binding).should.not.include nil
end
end