summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0xAB <0xAB@protonmail.com>2017-08-20 03:31:45 +0100
committer0xAB <0xAB@protonmail.com>2017-08-20 03:31:45 +0100
commitd4d6b2de86c2b61cfc14e4a4431c22dde61b2d0d (patch)
tree94e873e7124ad59dbf5e0ead721c2a169861f038
parent35e0593685d996bba982a3b94ff019d7bcb2be01 (diff)
parent590976efc75b502ab1fbd1f9b284ae8845de01cd (diff)
downloadpry-d4d6b2de86c2b61cfc14e4a4431c22dde61b2d0d.tar.gz
Merge remote-tracking branch 'pry/master' into feature/background-color-helpers
-rw-r--r--CHANGELOG.md3
-rw-r--r--lib/pry/basic_object.rb2
-rw-r--r--lib/pry/commands/whereami.rb2
-rw-r--r--lib/pry/config.rb15
-rw-r--r--lib/pry/config/behavior.rb4
-rw-r--r--lib/pry/input_completer.rb15
-rw-r--r--spec/completion_spec.rb60
-rw-r--r--spec/config_spec.rb14
8 files changed, 49 insertions, 66 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 70c53622..d6006416 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
### HEAD
-* Add text helpers for background colors ([#1624](https://github.com/pry/pry/pull/1624))
+* Fix string literal methods completion. ([#1590](https://github.com/pry/pry/pull/1590))
* Add alias 'whereami[?!]+' for 'whereami' command. ([#1597](https://github.com/pry/pry/pull/1597))
* Improve Ruby 2.4 support ([#1611](https://github.com/pry/pry/pull/1611)):
* Deprecated constants are hidden from `ls` output by default, use the `-d` switch to see them.
@@ -29,7 +29,6 @@
* Fixed error when Pry was trying to load incompatible versions of plugins ([#1312](https://github.com/pry/pry/issues/1312))
* Fixed bug when `hist --clear` led to ArgumentError ([#1340](https://github.com/pry/pry/pull/1340))
* Fixed the "uninitialized constant Pry::ObjectPath::StringScanner" exception during autocomplete ([#1330](https://github.com/pry/pry/issues/1330))
-* Secured usage of colours with special characters (RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE) in Pry::Helpers::Text ([#493](https://github.com/pry/pry/issues/493#issuecomment-39232771))
* Fixed regression with `pry -e` when it messes the terminal ([#1387](https://github.com/pry/pry/issues/1387))
* Fixed regression with space prefixes of expressions ([#1369](https://github.com/pry/pry/issues/1369))
* Introduced the new way to define hooks for commands (with `Pry.hooks.add_hook("{before,after}_commandName")`). The old way is deprecated, but still supported (with `Pry.commands.{before,after}_command`) ([#651](https://github.com/pry/pry/issues/651))
diff --git a/lib/pry/basic_object.rb b/lib/pry/basic_object.rb
index fa2dccfb..8a9de3ef 100644
--- a/lib/pry/basic_object.rb
+++ b/lib/pry/basic_object.rb
@@ -1,5 +1,5 @@
class Pry::BasicObject < BasicObject
- [:Kernel, :Pry].each do |constant|
+ [:Kernel, :Pry, :ArgumentError].each do |constant|
const_set constant, ::Object.const_get(constant)
end
include Kernel
diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb
index 810f407f..5676c5b9 100644
--- a/lib/pry/commands/whereami.rb
+++ b/lib/pry/commands/whereami.rb
@@ -193,5 +193,5 @@ class Pry
Pry::Commands.add_command(Pry::Command::Whereami)
Pry::Commands.alias_command '@', 'whereami'
- Pry::Commands.alias_command /whereami[!?]+/, 'whereami'
+ Pry::Commands.alias_command(/whereami[!?]+/, 'whereami')
end
diff --git a/lib/pry/config.rb b/lib/pry/config.rb
index 4f702863..ba2076c9 100644
--- a/lib/pry/config.rb
+++ b/lib/pry/config.rb
@@ -8,4 +8,19 @@ class Pry::Config < Pry::BasicObject
def self.shortcuts
Convenience::SHORTCUTS
end
+
+ READLINE_WORD_ESCAPE_STR = " \t\n`><=;|&{("
+
+ def input=(input)
+ @lookup['input'] = input
+
+ if input.respond_to?(:completer_word_break_characters=)
+ begin
+ input.completer_word_break_characters = READLINE_WORD_ESCAPE_STR
+ rescue ArgumentError
+ # Hi JRuby
+ input.basic_word_break_characters = READLINE_WORD_ESCAPE_STR
+ end
+ end
+ end
end
diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb
index f487637d..ee67ac3f 100644
--- a/lib/pry/config/behavior.rb
+++ b/lib/pry/config/behavior.rb
@@ -219,9 +219,11 @@ private
def __push(key,value)
unless singleton_class.method_defined? key
define_singleton_method(key) { self[key] }
+ end
+ unless singleton_class.method_defined? "#{key}="
define_singleton_method("#{key}=") { |val| @lookup[key] = val }
end
- @lookup[key] = value
+ send("#{key}=", value)
end
def __remove(key)
diff --git a/lib/pry/input_completer.rb b/lib/pry/input_completer.rb
index 859cb667..b33668c1 100644
--- a/lib/pry/input_completer.rb
+++ b/lib/pry/input_completer.rb
@@ -12,7 +12,8 @@ class Pry::InputCompleter
CONSTANT_OR_METHOD_REGEXP = /^([A-Z].*)::([^:.]*)$/
HEX_REGEXP = /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/
GLOBALVARIABLE_REGEXP = /^(\$[^.]*)$/
- VARIABLE_REGEXP = /^([^."].*)\.([^.]*)$/
+ VARIABLE_REGEXP = /^(.*[^.'"])\.([^.]*)$/
+ STRING_REGEXP = /^(.*["'])\.([^.]*)$/
ReservedWords = [
"BEGIN", "END",
@@ -39,12 +40,9 @@ class Pry::InputCompleter
"[]", "[]=", "^", "!", "!=", "!~"
]
- WORD_ESCAPE_STR = " \t\n\"\\'`><=;|&{("
-
def initialize(input, pry = nil)
@pry = 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
@@ -179,12 +177,13 @@ class Pry::InputCompleter
}
end
select_message(path, receiver, message, candidates.sort)
- when /^\.([^.]*)$/
- # Unknown(maybe String)
- receiver = ""
- message = Regexp.quote($1)
+ when STRING_REGEXP
+ receiver = $1
+ message = Regexp.quote($2)
candidates = String.instance_methods(true).collect(&:to_s)
select_message(path, receiver, message, candidates)
+ # TODO: Handle the target-less calls (e.g. with a space before the dot).
+ # when /^\.([^.]*)$/
else
candidates = eval(
"methods | private_methods | local_variables | " \
diff --git a/spec/completion_spec.rb b/spec/completion_spec.rb
index 58a193c9..40c73e5e 100644
--- a/spec/completion_spec.rb
+++ b/spec/completion_spec.rb
@@ -85,6 +85,13 @@ describe Pry::InputCompleter do
# Absolute Constant
completer_test(o).call('::IndexError')
+
+ # String
+ completer_test(Object.new).call('"".size')
+ completer_test(Object.new).call('abcd".size')
+
+ # Chain of calls starting with a string
+ completer_test(Object.new).call('abcd".size.times')
end
it 'should complete for target symbols' do
@@ -138,59 +145,6 @@ describe Pry::InputCompleter do
completer_test(b, pry).call('/Con')
end
- it 'should complete for stdlib symbols' do
-
- o = Object.new
- # Regexp
- completer_test(o).call('/foo/.extend')
-
- # Array
- completer_test(o).call('[1].push')
-
- # Hash
- completer_test(o).call('{"a" => "b"}.keys')
-
- # Proc
- completer_test(o).call('{2}.call')
-
- # Symbol
- completer_test(o).call(':symbol.to_s')
-
- # Absolute Constant
- completer_test(o).call('::IndexError')
- end
-
- it 'should complete for target symbols' do
- o = Object.new
-
- # Constant
- module Mod
- remove_const :Con if defined? Con
- Con = 'Constant'
- module Mod2
- end
- end
-
- completer_test(Mod).call('Con')
-
- # Constants or Class Methods
- completer_test(o).call('Mod::Con')
-
- # Symbol
- _foo = :symbol
- completer_test(o).call(':symbol')
-
- # Variables
- class << o
- attr_accessor :foo
- end
- o.foo = 'bar'
- completer_test(binding).call('o.foo')
-
- # trailing slash
- expect(Pry::InputCompleter.new(Readline).call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/')).to eq(true)
- end
-
it 'should complete for arbitrary scopes' do
module Bar
@barvar = :bar
diff --git a/spec/config_spec.rb b/spec/config_spec.rb
index d6961c80..9d5c3956 100644
--- a/spec/config_spec.rb
+++ b/spec/config_spec.rb
@@ -239,4 +239,18 @@ describe Pry::Config do
expect(local['output']).to eq(nil)
end
end
+
+ describe "#input=" do
+ it 'assigns a value on the key' do
+ local = Pry::Config.from_hash({})
+ local.input = :foo
+ expect(local.input).to eq(:foo)
+ end
+
+ it 'modifies input itself' do
+ input = OpenStruct.new(completer_word_break_characters: 'asdf')
+ local = Pry::Config.from_hash(input: input)
+ expect(input.completer_word_break_characters).to eq(Pry::Config::READLINE_WORD_ESCAPE_STR)
+ end
+ end
end