pry 0.12.2 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +158 -1
- data/LICENSE +1 -1
- data/README.md +331 -269
- data/bin/pry +5 -0
- data/lib/pry/basic_object.rb +8 -4
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +44 -55
- data/lib/pry/code/code_file.rb +28 -24
- data/lib/pry/code/code_range.rb +4 -2
- data/lib/pry/code/loc.rb +15 -8
- data/lib/pry/code.rb +40 -28
- data/lib/pry/code_object.rb +40 -38
- data/lib/pry/color_printer.rb +47 -46
- data/lib/pry/command.rb +166 -369
- data/lib/pry/command_set.rb +76 -73
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -81
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +71 -60
- data/lib/pry/commands/cat/file_formatter.rb +55 -49
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +61 -54
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +44 -39
- data/lib/pry/commands/clear_screen.rb +16 -10
- data/lib/pry/commands/code_collector.rb +148 -133
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +19 -30
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/edit.rb +184 -161
- data/lib/pry/commands/exit.rb +39 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -160
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -150
- data/lib/pry/commands/import_set.rb +20 -16
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls/constants.rb +59 -42
- data/lib/pry/commands/ls/formatter.rb +50 -46
- data/lib/pry/commands/ls/globals.rb +38 -34
- data/lib/pry/commands/ls/grep.rb +17 -13
- data/lib/pry/commands/ls/instance_vars.rb +29 -27
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -22
- data/lib/pry/commands/ls/local_vars.rb +38 -28
- data/lib/pry/commands/ls/ls_entity.rb +47 -51
- data/lib/pry/commands/ls/methods.rb +44 -43
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -22
- data/lib/pry/commands/ls.rb +124 -102
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +27 -22
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +55 -45
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +51 -51
- data/lib/pry/commands/shell_mode.rb +21 -17
- data/lib/pry/commands/show_doc.rb +80 -68
- data/lib/pry/commands/show_info.rb +189 -171
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -45
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/watch_expression.rb +89 -86
- data/lib/pry/commands/whereami.rb +156 -148
- data/lib/pry/commands/wtf.rb +75 -50
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/config.rb +307 -25
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +9 -7
- data/lib/pry/editor.rb +48 -21
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -16
- data/lib/pry/forwardable.rb +5 -1
- data/lib/pry/helpers/base_helpers.rb +68 -197
- data/lib/pry/helpers/command_helpers.rb +50 -61
- data/lib/pry/helpers/documentation_helpers.rb +21 -13
- data/lib/pry/helpers/options_helpers.rb +14 -7
- data/lib/pry/helpers/platform.rb +7 -5
- data/lib/pry/helpers/table.rb +33 -26
- data/lib/pry/helpers/text.rb +22 -19
- data/lib/pry/helpers.rb +2 -0
- data/lib/pry/history.rb +48 -56
- data/lib/pry/hooks.rb +21 -12
- data/lib/pry/indent.rb +54 -50
- data/lib/pry/input_completer.rb +248 -230
- data/lib/pry/input_lock.rb +8 -9
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method/disowned.rb +16 -4
- data/lib/pry/method/patcher.rb +12 -3
- data/lib/pry/method/weird_method_locator.rb +68 -44
- data/lib/pry/method.rb +141 -94
- data/lib/pry/object_path.rb +33 -25
- data/lib/pry/output.rb +121 -35
- data/lib/pry/pager.rb +41 -42
- data/lib/pry/prompt.rb +123 -54
- data/lib/pry/pry_class.rb +61 -103
- data/lib/pry/pry_instance.rb +217 -215
- data/lib/pry/repl.rb +18 -22
- data/lib/pry/repl_file_loader.rb +27 -21
- data/lib/pry/ring.rb +11 -6
- data/lib/pry/slop/commands.rb +164 -169
- data/lib/pry/slop/option.rb +172 -168
- data/lib/pry/slop.rb +574 -563
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +21 -12
- data/lib/pry/testable/mockable.rb +18 -10
- data/lib/pry/testable/pry_tester.rb +71 -56
- data/lib/pry/testable/utility.rb +29 -21
- data/lib/pry/testable/variables.rb +49 -43
- data/lib/pry/testable.rb +59 -61
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +27 -0
- data/lib/pry/wrapped_module/candidate.rb +21 -14
- data/lib/pry/wrapped_module.rb +51 -42
- data/lib/pry.rb +132 -119
- metadata +34 -34
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gem_readme.rb +0 -25
- data/lib/pry/commands/gem_search.rb +0 -40
- data/lib/pry/commands/gem_stats.rb +0 -83
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -54
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/config/behavior.rb +0 -255
- data/lib/pry/config/convenience.rb +0 -28
- data/lib/pry/config/default.rb +0 -159
- data/lib/pry/config/memoization.rb +0 -48
- data/lib/pry/platform.rb +0 -91
- data/lib/pry/plugins.rb +0 -122
- data/lib/pry/rubygem.rb +0 -84
- data/lib/pry/terminal.rb +0 -91
data/lib/pry/input_completer.rb
CHANGED
@@ -1,265 +1,283 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# taken from irb
|
2
4
|
# Implements tab completion for Readline in Pry
|
3
|
-
class Pry
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ReservedWords = [
|
18
|
-
"BEGIN", "END",
|
19
|
-
"alias", "and",
|
20
|
-
"begin", "break",
|
21
|
-
"case", "class",
|
22
|
-
"def", "defined", "do",
|
23
|
-
"else", "elsif", "end", "ensure",
|
24
|
-
"false", "for",
|
25
|
-
"if", "in",
|
26
|
-
"module",
|
27
|
-
"next", "nil", "not",
|
28
|
-
"or",
|
29
|
-
"redo", "rescue", "retry", "return",
|
30
|
-
"self", "super",
|
31
|
-
"then", "true",
|
32
|
-
"undef", "unless", "until",
|
33
|
-
"when", "while",
|
34
|
-
"yield" ]
|
5
|
+
class Pry
|
6
|
+
class InputCompleter
|
7
|
+
NUMERIC_REGEXP = /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/.freeze
|
8
|
+
ARRAY_REGEXP = /^([^\]]*\])\.([^.]*)$/.freeze
|
9
|
+
SYMBOL_REGEXP = /^(:[^:.]*)$/.freeze
|
10
|
+
SYMBOL_METHOD_CALL_REGEXP = /^(:[^:.]+)\.([^.]*)$/.freeze
|
11
|
+
REGEX_REGEXP = %r{^(/[^/]*/)\.([^.]*)$}.freeze
|
12
|
+
PROC_OR_HASH_REGEXP = /^([^\}]*\})\.([^.]*)$/.freeze
|
13
|
+
TOPLEVEL_LOOKUP_REGEXP = /^::([A-Z][^:\.\(]*)$/.freeze
|
14
|
+
CONSTANT_REGEXP = /^([A-Z][A-Za-z0-9]*)$/.freeze
|
15
|
+
CONSTANT_OR_METHOD_REGEXP = /^([A-Z].*)::([^:.]*)$/.freeze
|
16
|
+
HEX_REGEXP = /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/.freeze
|
17
|
+
GLOBALVARIABLE_REGEXP = /^(\$[^.]*)$/.freeze
|
18
|
+
VARIABLE_REGEXP = /^([^."].*)\.([^.]*)$/.freeze
|
35
19
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
20
|
+
RESERVED_WORDS = %w[
|
21
|
+
BEGIN END
|
22
|
+
alias and
|
23
|
+
begin break
|
24
|
+
case class
|
25
|
+
def defined do
|
26
|
+
else elsif end ensure
|
27
|
+
false for
|
28
|
+
if in
|
29
|
+
module
|
30
|
+
next nil not
|
31
|
+
or
|
32
|
+
redo rescue retry return
|
33
|
+
self super
|
34
|
+
then true
|
35
|
+
undef unless until
|
36
|
+
when while
|
37
|
+
yield
|
38
|
+
].freeze
|
41
39
|
|
42
|
-
|
40
|
+
WORD_ESCAPE_STR = " \t\n\"\\'`><=;|&{(".freeze
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
def initialize(input, pry = nil)
|
43
|
+
@pry = pry
|
44
|
+
@input = input
|
45
|
+
if @input.respond_to?(:basic_word_break_characters=)
|
46
|
+
@input.basic_word_break_characters = WORD_ESCAPE_STR
|
47
|
+
end
|
50
48
|
|
51
|
-
|
52
|
-
# Return a new completion proc for use by Readline.
|
53
|
-
#
|
54
|
-
def call(str, options = {})
|
55
|
-
custom_completions = options[:custom_completions] || []
|
56
|
-
# if there are multiple contexts e.g. cd 1/2/3
|
57
|
-
# get new target for 1/2 and find candidates for 3
|
58
|
-
path, input = build_path(str)
|
49
|
+
return unless @input.respond_to?(:completion_append_character=)
|
59
50
|
|
60
|
-
|
61
|
-
target = options[:target]
|
62
|
-
else
|
63
|
-
# Assume the user is tab-completing the 'cd' command
|
64
|
-
begin
|
65
|
-
target = Pry::ObjectPath.new(path.call, @pry.binding_stack).resolve.last
|
66
|
-
# but if that doesn't work, assume they're doing division with no spaces
|
67
|
-
rescue Pry::CommandError
|
68
|
-
target = options[:target]
|
69
|
-
end
|
51
|
+
@input.completion_append_character = nil
|
70
52
|
end
|
71
53
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
candidates = Array.instance_methods.collect(&:to_s)
|
85
|
-
select_message(path, receiver, message, candidates)
|
86
|
-
when PROC_OR_HASH_REGEXP # Proc or Hash
|
87
|
-
receiver = $1
|
88
|
-
message = Regexp.quote($2)
|
89
|
-
candidates = Proc.instance_methods.collect(&:to_s)
|
90
|
-
candidates |= Hash.instance_methods.collect(&:to_s)
|
91
|
-
select_message(path, receiver, message, candidates)
|
92
|
-
when SYMBOL_REGEXP # Symbol
|
93
|
-
if Symbol.respond_to?(:all_symbols)
|
94
|
-
sym = Regexp.quote($1)
|
95
|
-
candidates = Symbol.all_symbols.collect { |s| ":" << s.id2name }
|
96
|
-
candidates.grep(/^#{sym}/)
|
97
|
-
else
|
98
|
-
[]
|
99
|
-
end
|
100
|
-
when TOPLEVEL_LOOKUP_REGEXP # Absolute Constant or class methods
|
101
|
-
receiver = $1
|
102
|
-
candidates = Object.constants.collect(&:to_s)
|
103
|
-
candidates.grep(/^#{receiver}/).collect { |e| "::" << e }
|
104
|
-
when CONSTANT_REGEXP # Constant
|
105
|
-
message = $1
|
106
|
-
begin
|
107
|
-
context = target.eval("self")
|
108
|
-
context = context.class unless context.respond_to? :constants
|
109
|
-
candidates = context.constants.collect(&:to_s)
|
110
|
-
rescue
|
111
|
-
candidates = []
|
112
|
-
end
|
113
|
-
candidates = candidates.grep(/^#{message}/).collect(&path)
|
114
|
-
when CONSTANT_OR_METHOD_REGEXP # Constant or class methods
|
115
|
-
receiver = $1
|
116
|
-
message = Regexp.quote($2)
|
117
|
-
begin
|
118
|
-
candidates = eval("#{receiver}.constants.collect(&:to_s)", bind)
|
119
|
-
candidates |= eval("#{receiver}.methods.collect(&:to_s)", bind)
|
120
|
-
rescue Pry::RescuableException
|
121
|
-
candidates = []
|
122
|
-
end
|
123
|
-
candidates.grep(/^#{message}/).collect { |e| receiver + "::" + e }
|
124
|
-
when SYMBOL_METHOD_CALL_REGEXP # method call on a Symbol
|
125
|
-
receiver = $1
|
126
|
-
message = Regexp.quote($2)
|
127
|
-
candidates = Symbol.instance_methods.collect(&:to_s)
|
128
|
-
select_message(path, receiver, message, candidates)
|
129
|
-
when NUMERIC_REGEXP
|
130
|
-
# Numeric
|
131
|
-
receiver = $1
|
132
|
-
message = Regexp.quote($5)
|
133
|
-
begin
|
134
|
-
candidates = eval(receiver, bind).methods.collect(&:to_s)
|
135
|
-
rescue Pry::RescuableException
|
136
|
-
candidates = []
|
137
|
-
end
|
138
|
-
select_message(path, receiver, message, candidates)
|
139
|
-
when HEX_REGEXP
|
140
|
-
# Numeric(0xFFFF)
|
141
|
-
receiver = $1
|
142
|
-
message = Regexp.quote($2)
|
54
|
+
# Return a new completion proc for use by Readline.
|
55
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
56
|
+
def call(str, options = {})
|
57
|
+
custom_completions = options[:custom_completions] || []
|
58
|
+
# if there are multiple contexts e.g. cd 1/2/3
|
59
|
+
# get new target for 1/2 and find candidates for 3
|
60
|
+
path, input = build_path(str)
|
61
|
+
|
62
|
+
if path.call.empty?
|
63
|
+
target = options[:target]
|
64
|
+
else
|
65
|
+
# Assume the user is tab-completing the 'cd' command
|
143
66
|
begin
|
144
|
-
|
145
|
-
|
146
|
-
|
67
|
+
target = Pry::ObjectPath.new(path.call, @pry.binding_stack).resolve.last
|
68
|
+
# but if that doesn't work, assume they're doing division with no spaces
|
69
|
+
rescue Pry::CommandError
|
70
|
+
target = options[:target]
|
147
71
|
end
|
148
|
-
|
149
|
-
when GLOBALVARIABLE_REGEXP # global
|
150
|
-
regmessage = Regexp.new(Regexp.quote($1))
|
151
|
-
candidates = global_variables.collect(&:to_s).grep(regmessage)
|
152
|
-
when VARIABLE_REGEXP # variable
|
153
|
-
receiver = $1
|
154
|
-
message = Regexp.quote($2)
|
155
|
-
|
156
|
-
gv = eval("global_variables", bind).collect(&:to_s)
|
157
|
-
lv = eval("local_variables", bind).collect(&:to_s)
|
158
|
-
cv = eval("self.class.constants", bind).collect(&:to_s)
|
72
|
+
end
|
159
73
|
|
160
|
-
|
161
|
-
|
162
|
-
|
74
|
+
begin
|
75
|
+
bind = target
|
76
|
+
# Complete stdlib symbols
|
77
|
+
case input
|
78
|
+
when REGEX_REGEXP # Regexp
|
79
|
+
receiver = Regexp.last_match(1)
|
80
|
+
message = Regexp.quote(Regexp.last_match(2))
|
81
|
+
candidates = Regexp.instance_methods.collect(&:to_s)
|
82
|
+
select_message(path, receiver, message, candidates)
|
83
|
+
when ARRAY_REGEXP # Array
|
84
|
+
receiver = Regexp.last_match(1)
|
85
|
+
message = Regexp.quote(Regexp.last_match(2))
|
86
|
+
candidates = Array.instance_methods.collect(&:to_s)
|
87
|
+
select_message(path, receiver, message, candidates)
|
88
|
+
when PROC_OR_HASH_REGEXP # Proc or Hash
|
89
|
+
receiver = Regexp.last_match(1)
|
90
|
+
message = Regexp.quote(Regexp.last_match(2))
|
91
|
+
candidates = Proc.instance_methods.collect(&:to_s)
|
92
|
+
candidates |= Hash.instance_methods.collect(&:to_s)
|
93
|
+
select_message(path, receiver, message, candidates)
|
94
|
+
when SYMBOL_REGEXP # Symbol
|
95
|
+
if Symbol.respond_to?(:all_symbols)
|
96
|
+
sym = Regexp.quote(Regexp.last_match(1))
|
97
|
+
candidates = Symbol.all_symbols.collect { |s| ":" + s.id2name }
|
98
|
+
candidates.grep(/^#{sym}/)
|
99
|
+
else
|
100
|
+
[]
|
101
|
+
end
|
102
|
+
when TOPLEVEL_LOOKUP_REGEXP # Absolute Constant or class methods
|
103
|
+
receiver = Regexp.last_match(1)
|
104
|
+
candidates = Object.constants.collect(&:to_s)
|
105
|
+
candidates.grep(/^#{receiver}/).collect { |e| "::" + e }
|
106
|
+
when CONSTANT_REGEXP # Constant
|
107
|
+
message = Regexp.last_match(1)
|
108
|
+
begin
|
109
|
+
context = target.eval("self")
|
110
|
+
context = context.class unless context.respond_to? :constants
|
111
|
+
candidates = context.constants.collect(&:to_s)
|
112
|
+
rescue StandardError
|
113
|
+
candidates = []
|
114
|
+
end
|
115
|
+
candidates = candidates.grep(/^#{message}/).collect(&path)
|
116
|
+
when CONSTANT_OR_METHOD_REGEXP # Constant or class methods
|
117
|
+
receiver = Regexp.last_match(1)
|
118
|
+
message = Regexp.quote(Regexp.last_match(2))
|
163
119
|
begin
|
164
|
-
candidates = eval(
|
120
|
+
candidates = eval( # rubocop:disable Security/Eval
|
121
|
+
"#{receiver}.constants.collect(&:to_s)", bind, __FILE__, __LINE__
|
122
|
+
)
|
123
|
+
candidates |= eval( # rubocop:disable Security/Eval
|
124
|
+
"#{receiver}.methods.collect(&:to_s)", bind, __FILE__, __LINE__
|
125
|
+
)
|
165
126
|
rescue Pry::RescuableException
|
166
127
|
candidates = []
|
167
128
|
end
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
129
|
+
candidates.grep(/^#{message}/).collect { |e| receiver + "::" + e }
|
130
|
+
when SYMBOL_METHOD_CALL_REGEXP # method call on a Symbol
|
131
|
+
receiver = Regexp.last_match(1)
|
132
|
+
message = Regexp.quote(Regexp.last_match(2))
|
133
|
+
candidates = Symbol.instance_methods.collect(&:to_s)
|
134
|
+
select_message(path, receiver, message, candidates)
|
135
|
+
when NUMERIC_REGEXP
|
136
|
+
# Numeric
|
137
|
+
receiver = Regexp.last_match(1)
|
138
|
+
message = Regexp.quote(Regexp.last_match(5))
|
139
|
+
begin
|
140
|
+
# rubocop:disable Security/Eval
|
141
|
+
candidates = eval(receiver, bind).methods.collect(&:to_s)
|
142
|
+
# rubocop:enable Security/Eval
|
143
|
+
rescue Pry::RescuableException
|
144
|
+
candidates = []
|
145
|
+
end
|
146
|
+
select_message(path, receiver, message, candidates)
|
147
|
+
when HEX_REGEXP
|
148
|
+
# Numeric(0xFFFF)
|
149
|
+
receiver = Regexp.last_match(1)
|
150
|
+
message = Regexp.quote(Regexp.last_match(2))
|
151
|
+
begin
|
152
|
+
# rubocop:disable Security/Eval
|
153
|
+
candidates = eval(receiver, bind).methods.collect(&:to_s)
|
154
|
+
# rubocop:enable Security/Eval
|
155
|
+
rescue Pry::RescuableException
|
156
|
+
candidates = []
|
157
|
+
end
|
158
|
+
select_message(path, receiver, message, candidates)
|
159
|
+
when GLOBALVARIABLE_REGEXP # global
|
160
|
+
regmessage = Regexp.new(Regexp.quote(Regexp.last_match(1)))
|
161
|
+
candidates = global_variables.collect(&:to_s).grep(regmessage)
|
162
|
+
when VARIABLE_REGEXP # variable
|
163
|
+
receiver = Regexp.last_match(1)
|
164
|
+
message = Regexp.quote(Regexp.last_match(2))
|
175
165
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
166
|
+
gv = eval("global_variables", bind, __FILE__, __LINE__).collect(&:to_s)
|
167
|
+
lv = eval("local_variables", bind, __FILE__, __LINE__).collect(&:to_s)
|
168
|
+
cv = eval("self.class.constants", bind, __FILE__, __LINE__).collect(&:to_s)
|
169
|
+
|
170
|
+
if (gv | lv | cv).include?(receiver) || /^[A-Z]/ =~ receiver && /\./ !~ receiver
|
171
|
+
# foo.func and foo is local var. OR
|
172
|
+
# Foo::Bar.func
|
173
|
+
begin
|
174
|
+
candidates = eval( # rubocop:disable Security/Eval
|
175
|
+
"#{receiver}.methods", bind, __FILE__, __LINE__
|
176
|
+
).collect(&:to_s)
|
177
|
+
rescue Pry::RescuableException
|
178
|
+
candidates = []
|
180
179
|
end
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
180
|
+
else
|
181
|
+
# func1.func2
|
182
|
+
require 'set'
|
183
|
+
candidates = Set.new
|
184
|
+
to_ignore = ignored_modules
|
185
|
+
ObjectSpace.each_object(Module) do |m|
|
186
|
+
next if begin
|
187
|
+
to_ignore.include?(m)
|
188
|
+
rescue StandardError
|
189
|
+
true
|
190
|
+
end
|
191
|
+
|
192
|
+
# jruby doesn't always provide #instance_methods() on each
|
193
|
+
# object.
|
194
|
+
if m.respond_to?(:instance_methods)
|
195
|
+
candidates.merge m.instance_methods(false).collect(&:to_s)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
select_message(path, receiver, message, candidates.sort)
|
200
|
+
when /^\.([^.]*)$/
|
201
|
+
# Unknown(maybe String)
|
202
|
+
receiver = ""
|
203
|
+
message = Regexp.quote(Regexp.last_match(1))
|
204
|
+
candidates = String.instance_methods(true).collect(&:to_s)
|
205
|
+
select_message(path, receiver, message, candidates)
|
206
|
+
else
|
207
|
+
candidates = eval(
|
208
|
+
"methods | private_methods | local_variables | " \
|
209
|
+
"self.class.constants | instance_variables",
|
210
|
+
bind, __FILE__, __LINE__ - 2
|
211
|
+
).collect(&:to_s)
|
196
212
|
|
197
|
-
|
198
|
-
|
213
|
+
if eval("respond_to?(:class_variables)", bind, __FILE__, __LINE__)
|
214
|
+
candidates += eval(
|
215
|
+
"class_variables", bind, __FILE__, __LINE__
|
216
|
+
).collect(&:to_s)
|
217
|
+
end
|
218
|
+
candidates =
|
219
|
+
(candidates | RESERVED_WORDS | custom_completions)
|
220
|
+
.grep(/^#{Regexp.quote(input)}/)
|
221
|
+
candidates.collect(&path)
|
199
222
|
end
|
200
|
-
|
201
|
-
|
223
|
+
rescue Pry::RescuableException
|
224
|
+
[]
|
202
225
|
end
|
203
|
-
rescue Pry::RescuableException
|
204
|
-
[]
|
205
226
|
end
|
206
|
-
|
227
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
207
228
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
when /^[a-zA-Z_]/
|
212
|
-
path.call(receiver + "." << e)
|
213
|
-
when /^[0-9]/
|
214
|
-
when *Operators
|
215
|
-
#receiver + " " << e
|
216
|
-
end
|
217
|
-
}.compact
|
218
|
-
end
|
229
|
+
def select_message(path, receiver, message, candidates)
|
230
|
+
candidates.grep(/^#{message}/).collect do |e|
|
231
|
+
next unless e =~ /^[a-zA-Z_]/
|
219
232
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
#
|
225
|
-
|
233
|
+
path.call(receiver + "." + e)
|
234
|
+
end.compact
|
235
|
+
end
|
236
|
+
|
237
|
+
# build_path seperates the input into two parts: path and input.
|
238
|
+
# input is the partial string that should be completed
|
239
|
+
# path is a proc that takes an input and builds a full path.
|
240
|
+
def build_path(input)
|
241
|
+
# check to see if the input is a regex
|
242
|
+
return proc { |i| i.to_s }, input if input[%r{/\.}]
|
226
243
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
244
|
+
trailing_slash = input.end_with?('/')
|
245
|
+
contexts = input.chomp('/').split(%r{/})
|
246
|
+
input = contexts[-1]
|
247
|
+
path = proc do |i|
|
248
|
+
p = contexts[0..-2].push(i).join('/')
|
249
|
+
p += '/' if trailing_slash && !i.nil?
|
250
|
+
p
|
251
|
+
end
|
252
|
+
[path, input]
|
234
253
|
end
|
235
|
-
return path, input
|
236
|
-
end
|
237
254
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
255
|
+
def ignored_modules
|
256
|
+
# We could cache the result, but IRB is not loaded by default.
|
257
|
+
# And this is very fast anyway.
|
258
|
+
# By using this approach, we avoid Module#name calls, which are
|
259
|
+
# relatively slow when there are a lot of anonymous modules defined.
|
260
|
+
s = Set.new
|
244
261
|
|
245
|
-
|
246
|
-
|
262
|
+
scanner = lambda do |m|
|
263
|
+
next if s.include?(m) # IRB::ExtendCommandBundle::EXCB recurses.
|
247
264
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
265
|
+
s << m
|
266
|
+
m.constants(false).each do |c|
|
267
|
+
value = m.const_get(c)
|
268
|
+
scanner.call(value) if value.is_a?(Module)
|
269
|
+
end
|
252
270
|
end
|
253
|
-
end
|
254
271
|
|
255
|
-
|
256
|
-
|
257
|
-
|
272
|
+
# FIXME: Add Pry here as well?
|
273
|
+
[:IRB, :SLex, :RubyLex, :RubyToken].each do |module_name|
|
274
|
+
next unless Object.const_defined?(module_name)
|
258
275
|
|
259
|
-
|
260
|
-
|
276
|
+
scanner.call(Object.const_get(module_name))
|
277
|
+
end
|
261
278
|
|
262
|
-
|
263
|
-
|
279
|
+
s.delete(IRB::Context) if defined?(IRB::Context)
|
280
|
+
s
|
281
|
+
end
|
264
282
|
end
|
265
283
|
end
|
data/lib/pry/input_lock.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
# There is one InputLock per input (such as STDIN) as two REPLs on the same
|
3
5
|
# input makes things delirious. InputLock serializes accesses to the input so
|
4
6
|
# that threads to not conflict with each other. The latest thread to request
|
5
7
|
# ownership of the input wins.
|
6
8
|
class InputLock
|
7
|
-
class Interrupt < Exception; end
|
9
|
+
class Interrupt < Exception; end # rubocop:disable Lint/InheritException
|
8
10
|
|
9
11
|
class << self
|
10
12
|
attr_accessor :input_locks
|
@@ -33,7 +35,7 @@ class Pry
|
|
33
35
|
|
34
36
|
# Adds ourselves to the ownership list. The last one in the list may access
|
35
37
|
# the input through interruptible_region().
|
36
|
-
def __with_ownership
|
38
|
+
def __with_ownership
|
37
39
|
@mutex.synchronize do
|
38
40
|
# Three cases:
|
39
41
|
# 1) There are no owners, in this case we are good to go.
|
@@ -56,8 +58,7 @@ class Pry
|
|
56
58
|
@owners << Thread.current
|
57
59
|
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
+
yield
|
61
62
|
ensure
|
62
63
|
@mutex.synchronize do
|
63
64
|
# We are releasing any desire to have the input ownership by removing
|
@@ -74,7 +75,7 @@ class Pry
|
|
74
75
|
def with_ownership(&block)
|
75
76
|
# If we are in a nested with_ownership() call (nested pry context), we do nothing.
|
76
77
|
nested = @mutex.synchronize { @owners.include?(Thread.current) }
|
77
|
-
nested ?
|
78
|
+
nested ? yield : __with_ownership(&block)
|
78
79
|
end
|
79
80
|
|
80
81
|
def enter_interruptible_region
|
@@ -104,14 +105,13 @@ class Pry
|
|
104
105
|
retry
|
105
106
|
end
|
106
107
|
|
107
|
-
def interruptible_region
|
108
|
+
def interruptible_region
|
108
109
|
enter_interruptible_region
|
109
110
|
|
110
111
|
# XXX Note that there is a chance that we get the interrupt right after
|
111
112
|
# the readline call succeeded, but we'll never know, and we will retry the
|
112
113
|
# call, discarding that piece of input.
|
113
|
-
|
114
|
-
|
114
|
+
yield
|
115
115
|
rescue Interrupt
|
116
116
|
# We were asked to back off. The one requesting the interrupt will be
|
117
117
|
# waiting on the conditional for the interruptible flag to change to false.
|
@@ -122,7 +122,6 @@ class Pry
|
|
122
122
|
leave_interruptible_region
|
123
123
|
sleep 0.01
|
124
124
|
retry
|
125
|
-
|
126
125
|
ensure
|
127
126
|
leave_interruptible_region
|
128
127
|
end
|
data/lib/pry/inspector.rb
CHANGED
@@ -1,27 +1,39 @@
|
|
1
|
-
|
2
|
-
MAP = {
|
3
|
-
"default" => {
|
4
|
-
value: Pry::DEFAULT_PRINT,
|
5
|
-
description: <<-DESCRIPTION.each_line.map(&:lstrip!)
|
6
|
-
The default Pry inspector. It has paging and color support, and uses
|
7
|
-
pretty_inspect when printing an object.
|
8
|
-
DESCRIPTION
|
9
|
-
},
|
1
|
+
# frozen_string_literal: true
|
10
2
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
3
|
+
class Pry
|
4
|
+
class Inspector
|
5
|
+
MAP = {
|
6
|
+
"default" => {
|
7
|
+
value: Pry.config.print,
|
8
|
+
description: <<-DESCRIPTION.each_line.map(&:lstrip!)
|
9
|
+
The default Pry inspector. It has paging and color support, and uses
|
10
|
+
pretty_inspect when printing an object.
|
11
|
+
DESCRIPTION
|
12
|
+
},
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
"simple" => {
|
15
|
+
value: proc do |output, value|
|
16
|
+
begin
|
17
|
+
output.puts value.inspect
|
18
|
+
rescue RescuableException
|
19
|
+
output.puts "unknown"
|
20
|
+
end
|
21
|
+
end,
|
22
|
+
description: <<-DESCRIPTION.each_line.map(&:lstrip)
|
23
|
+
A simple inspector that uses #puts and #inspect when printing an
|
24
|
+
object. It has no pager, color, or pretty_inspect support.
|
25
|
+
DESCRIPTION
|
26
|
+
},
|
27
|
+
|
28
|
+
"clipped" => {
|
29
|
+
value: proc do |output, value|
|
30
|
+
output.puts Pry.view_clip(value, id: true)
|
31
|
+
end,
|
32
|
+
description: <<-DESCRIPTION.each_line.map(&:lstrip)
|
33
|
+
The clipped inspector has the same features as the 'simple' inspector
|
34
|
+
but prints large objects as a smaller string.
|
35
|
+
DESCRIPTION
|
36
|
+
}
|
37
|
+
}.freeze
|
38
|
+
end
|
27
39
|
end
|