irb 1.17.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/doc/Index.md +2 -2
- data/lib/irb/color.rb +71 -8
- data/lib/irb/command/base.rb +35 -0
- data/lib/irb/command/internal_helpers.rb +6 -3
- data/lib/irb/command/load.rb +4 -4
- data/lib/irb/command/ls.rb +6 -4
- data/lib/irb/command/measure.rb +8 -2
- data/lib/irb/command/pushws.rb +10 -4
- data/lib/irb/completion.rb +48 -22
- data/lib/irb/context.rb +2 -2
- data/lib/irb/ext/eval_history.rb +3 -3
- data/lib/irb/ext/loader.rb +0 -3
- data/lib/irb/history.rb +25 -25
- data/lib/irb/init.rb +9 -3
- data/lib/irb/input-method.rb +162 -111
- data/lib/irb/nesting_parser.rb +1 -0
- data/lib/irb/pager.rb +8 -0
- data/lib/irb/ruby-lex.rb +164 -264
- data/lib/irb/ruby_logo.aa +4 -0
- data/lib/irb/source_finder.rb +5 -14
- data/lib/irb/startup_message.rb +82 -0
- data/lib/irb/version.rb +2 -2
- data/lib/irb.rb +16 -7
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1659fa380cb8e67dca7525396830d9319b6aaf5c1c4d12523a6434169f1ed442
|
|
4
|
+
data.tar.gz: 45978084c34df26dc1b4b963f4cceb1f40e9ec051088a8f75adecfc40f6a69c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8fb9da5edd1a1ae78623dff1d3738e99ce3d25a9c0b124b5a5e44333233a68542c1f140f700d26d4e9563cb4fafe1e3135911760bf0fb286d5f0a6bb573f1ec
|
|
7
|
+
data.tar.gz: d5cb86a37083e309207fee3809114aec127d90e5f54a6ec9539b1f2da3355bbe00618acd2150dc36bb98907f6e3461cab1e2b024dd2572d7453ede51c816abb5
|
data/Gemfile
CHANGED
data/doc/Index.md
CHANGED
|
@@ -98,7 +98,7 @@ To learn more about debugging with IRB, see [Debugging with IRB](#label-Debuggin
|
|
|
98
98
|
At startup, IRB:
|
|
99
99
|
|
|
100
100
|
1. Interprets (as Ruby code) the content of the [configuration file](rdoc-ref:Configurations.md) (if given).
|
|
101
|
-
2. Constructs the initial session context from [hash IRB.conf](
|
|
101
|
+
2. Constructs the initial session context from [hash IRB.conf](rdoc-ref:Configurations.md@Hash+IRB.conf) and from default values; the hash content may have been affected by [command-line options](#command-line-options), and by direct assignments in the configuration file.
|
|
102
102
|
3. Assigns the context to variable `conf`.
|
|
103
103
|
4. Assigns command-line arguments to variable `ARGV`.
|
|
104
104
|
5. Prints the prompt.
|
|
@@ -692,7 +692,7 @@ Command-line option `-U` sets both to UTF-8.
|
|
|
692
692
|
|
|
693
693
|
## Contributing
|
|
694
694
|
|
|
695
|
-
See [CONTRIBUTING.md](https://github.com/ruby/irb/blob/
|
|
695
|
+
See [CONTRIBUTING.md](https://github.com/ruby/irb/blob/master/CONTRIBUTING.md) for more information.
|
|
696
696
|
|
|
697
697
|
## Extending IRB
|
|
698
698
|
|
data/lib/irb/color.rb
CHANGED
|
@@ -69,6 +69,7 @@ module IRB # :nodoc:
|
|
|
69
69
|
KEYWORD_IN: [GREEN],
|
|
70
70
|
KEYWORD_DEF: [GREEN],
|
|
71
71
|
KEYWORD_DO: [GREEN],
|
|
72
|
+
KEYWORD_DO_BLOCK: [GREEN],
|
|
72
73
|
KEYWORD_DO_LOOP: [GREEN],
|
|
73
74
|
KEYWORD_FOR: [GREEN],
|
|
74
75
|
KEYWORD_BEGIN: [GREEN],
|
|
@@ -98,20 +99,22 @@ module IRB # :nodoc:
|
|
|
98
99
|
REGEXP_BEGIN: [RED, BOLD],
|
|
99
100
|
REGEXP_END: [RED, BOLD],
|
|
100
101
|
STRING_BEGIN: [RED, BOLD],
|
|
102
|
+
XSTRING_BEGIN: [RED, BOLD],
|
|
101
103
|
STRING_CONTENT: [RED],
|
|
102
104
|
STRING_END: [RED, BOLD],
|
|
103
105
|
__END__: [GREEN],
|
|
104
106
|
# tokens from syntax tree traversal
|
|
105
|
-
method_name: [
|
|
107
|
+
method_name: [CYAN, BOLD],
|
|
108
|
+
message_name: [CYAN],
|
|
106
109
|
symbol: [YELLOW],
|
|
107
110
|
# special colorization
|
|
108
111
|
error: [RED, REVERSE],
|
|
109
|
-
const_env: [CYAN, BOLD],
|
|
110
112
|
}.transform_values do |styles|
|
|
111
113
|
styles.map { |style| "\e[#{style}m" }.join
|
|
112
114
|
end
|
|
113
115
|
CLEAR_SEQ = "\e[#{CLEAR}m"
|
|
114
|
-
|
|
116
|
+
OPERATORS = %i(!= !~ =~ == === <=> > >= < <= & | ^ >> << - + % / * ** -@ +@ ~ ! [] []=)
|
|
117
|
+
private_constant :TOKEN_SEQS, :CLEAR_SEQ, :OPERATORS
|
|
115
118
|
|
|
116
119
|
class << self
|
|
117
120
|
def colorable?
|
|
@@ -168,12 +171,13 @@ module IRB # :nodoc:
|
|
|
168
171
|
# IRB::ColorPrinter skips colorizing syntax invalid fragments
|
|
169
172
|
return Reline::Unicode.escape_for_print(code) if ignore_error && !result.success?
|
|
170
173
|
|
|
174
|
+
prism_node, prism_tokens = result.value
|
|
171
175
|
errors = result.errors
|
|
176
|
+
|
|
172
177
|
unless complete
|
|
173
|
-
errors = errors
|
|
178
|
+
errors = filter_incomplete_code_errors(errors, prism_tokens)
|
|
174
179
|
end
|
|
175
180
|
|
|
176
|
-
prism_node, prism_tokens = result.value
|
|
177
181
|
visitor = ColorizeVisitor.new
|
|
178
182
|
prism_node.accept(visitor)
|
|
179
183
|
|
|
@@ -202,9 +206,7 @@ module IRB # :nodoc:
|
|
|
202
206
|
next if start_line - 1 < line_index || (start_line - 1 == line_index && start_column < col)
|
|
203
207
|
|
|
204
208
|
flush.call(start_line - 1, start_column)
|
|
205
|
-
if type == :
|
|
206
|
-
color = TOKEN_SEQS[:const_env]
|
|
207
|
-
elsif type == :__END__
|
|
209
|
+
if type == :__END__
|
|
208
210
|
color = TOKEN_SEQS[type]
|
|
209
211
|
end_line = start_line
|
|
210
212
|
value = '__END__'
|
|
@@ -251,6 +253,36 @@ module IRB # :nodoc:
|
|
|
251
253
|
super
|
|
252
254
|
end
|
|
253
255
|
|
|
256
|
+
def visit_alias_method_node(node)
|
|
257
|
+
dispatch_alias_method_name node.new_name
|
|
258
|
+
dispatch_alias_method_name node.old_name
|
|
259
|
+
super
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def visit_implicit_node(_node)
|
|
263
|
+
# Label of implicit nodes are colored as LABEL in visit_symbol_node.
|
|
264
|
+
# We need to prevent value part from being colored with another type.
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def visit_call_node(node)
|
|
268
|
+
if node.call_operator_loc.nil? && OPERATORS.include?(node.name)
|
|
269
|
+
# Operators should not be colored as method call
|
|
270
|
+
elsif (node.call_operator_loc.nil? || node.call_operator_loc.slice == "::") &&
|
|
271
|
+
/\A\p{Upper}/.match?(node.name)
|
|
272
|
+
# Constant-like methods should not be colored as method call
|
|
273
|
+
else
|
|
274
|
+
dispatch node.message_loc, :message_name
|
|
275
|
+
end
|
|
276
|
+
super
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def visit_call_operator_write_node(node)
|
|
280
|
+
dispatch node.message_loc, :message_name
|
|
281
|
+
super
|
|
282
|
+
end
|
|
283
|
+
alias visit_call_and_write_node visit_call_operator_write_node
|
|
284
|
+
alias visit_call_or_write_node visit_call_operator_write_node
|
|
285
|
+
|
|
254
286
|
def visit_interpolated_symbol_node(node)
|
|
255
287
|
dispatch node.opening_loc, :symbol
|
|
256
288
|
node.parts.each do |part|
|
|
@@ -278,10 +310,41 @@ module IRB # :nodoc:
|
|
|
278
310
|
dispatch node.closing_loc, :symbol
|
|
279
311
|
end
|
|
280
312
|
end
|
|
313
|
+
|
|
314
|
+
private
|
|
315
|
+
|
|
316
|
+
def dispatch_alias_method_name(node)
|
|
317
|
+
if node.type == :symbol_node && node.opening_loc.nil?
|
|
318
|
+
dispatch node.value_loc, :method_name
|
|
319
|
+
end
|
|
320
|
+
end
|
|
281
321
|
end
|
|
282
322
|
|
|
283
323
|
private
|
|
284
324
|
|
|
325
|
+
FILTERED_ERROR_TYPES = [
|
|
326
|
+
:class_name, :module_name, # `class`, `class owner_module`
|
|
327
|
+
:write_target_unexpected, # `a, b`
|
|
328
|
+
:parameter_wild_loose_comma, # `def f(a,`
|
|
329
|
+
:argument_no_forwarding_star, # `[*`
|
|
330
|
+
:argument_no_forwarding_star_star, # `f(**`
|
|
331
|
+
:argument_no_forwarding_ampersand, # `f(&`
|
|
332
|
+
:def_endless, # `def f =`
|
|
333
|
+
:embdoc_term, # `=begin`
|
|
334
|
+
]
|
|
335
|
+
|
|
336
|
+
# Filter out syntax errors that are likely to be caused by incomplete code, to avoid showing misleading error highlights to users.
|
|
337
|
+
def filter_incomplete_code_errors(errors, tokens)
|
|
338
|
+
last_non_comment_space_token, = tokens.reverse_each.find do |t,|
|
|
339
|
+
t.type != :COMMENT && t.type != :EOF && t.type != :IGNORED_NEWLINE && t.type != :NEWLINE
|
|
340
|
+
end
|
|
341
|
+
last_offset = last_non_comment_space_token ? last_non_comment_space_token.location.end_offset : 0
|
|
342
|
+
errors.reject do |error|
|
|
343
|
+
error.message.match?(/\Aexpected a|unexpected end-of-input|unterminated/) ||
|
|
344
|
+
(error.location.end_offset == last_offset && FILTERED_ERROR_TYPES.include?(error.type))
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
285
348
|
def without_circular_ref(obj, seen:, &block)
|
|
286
349
|
return false if seen.key?(obj)
|
|
287
350
|
seen[obj] = true
|
data/lib/irb/command/base.rb
CHANGED
|
@@ -37,11 +37,46 @@ module IRB
|
|
|
37
37
|
puts e.message
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
# Returns formatted lines for display in the doc dialog popup.
|
|
41
|
+
def doc_dialog_content(name, width)
|
|
42
|
+
lines = []
|
|
43
|
+
lines << Color.colorize(name, [:BOLD, :BLUE]) + Color.colorize(" (command)", [:CYAN])
|
|
44
|
+
lines << ""
|
|
45
|
+
lines.concat(wrap_lines(description, width))
|
|
46
|
+
if help_message
|
|
47
|
+
lines << ""
|
|
48
|
+
lines.concat(wrap_lines(help_message, width))
|
|
49
|
+
end
|
|
50
|
+
lines
|
|
51
|
+
end
|
|
52
|
+
|
|
40
53
|
private
|
|
41
54
|
|
|
42
55
|
def highlight(text)
|
|
43
56
|
Color.colorize(text, [:BOLD, :BLUE])
|
|
44
57
|
end
|
|
58
|
+
|
|
59
|
+
def wrap_lines(text, width)
|
|
60
|
+
text.lines.flat_map do |line|
|
|
61
|
+
line = line.chomp
|
|
62
|
+
next [''] if line.empty?
|
|
63
|
+
next [line] if line.length <= width
|
|
64
|
+
|
|
65
|
+
indent = line[/\A\s*/]
|
|
66
|
+
parts = line.strip.split(/(\s+)/)
|
|
67
|
+
result = []
|
|
68
|
+
current = indent.dup
|
|
69
|
+
parts.each do |part|
|
|
70
|
+
if current != indent && current.length + part.length > width
|
|
71
|
+
result << current.rstrip
|
|
72
|
+
current = indent.dup
|
|
73
|
+
end
|
|
74
|
+
current << part unless current == indent && part.match?(/\A\s+\z/)
|
|
75
|
+
end
|
|
76
|
+
result << current.rstrip unless current == indent
|
|
77
|
+
result
|
|
78
|
+
end
|
|
79
|
+
end
|
|
45
80
|
end
|
|
46
81
|
|
|
47
82
|
def initialize(irb_context)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'prism'
|
|
4
|
+
|
|
3
5
|
module IRB
|
|
4
6
|
module Command
|
|
5
7
|
# Internal use only, for default command's backward compatibility.
|
|
@@ -7,9 +9,10 @@ module IRB
|
|
|
7
9
|
def unwrap_string_literal(str)
|
|
8
10
|
return if str.empty?
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
result = Prism.parse(str)
|
|
13
|
+
body = result.value.statements.body
|
|
14
|
+
if result.success? && body.size == 1 && body.first.is_a?(Prism::StringNode)
|
|
15
|
+
body.first.unescaped
|
|
13
16
|
else
|
|
14
17
|
str
|
|
15
18
|
end
|
data/lib/irb/command/load.rb
CHANGED
|
@@ -45,7 +45,7 @@ module IRB
|
|
|
45
45
|
def execute_internal(file_name = nil)
|
|
46
46
|
raise_cmd_argument_error unless file_name
|
|
47
47
|
|
|
48
|
-
rex = Regexp.new("#{Regexp.
|
|
48
|
+
rex = Regexp.new("(?:\\A|/)#{Regexp.escape(file_name)}(?:\\.o|\\.rb)?\\z")
|
|
49
49
|
return false if $".find{|f| f =~ rex}
|
|
50
50
|
|
|
51
51
|
case file_name
|
|
@@ -58,15 +58,15 @@ module IRB
|
|
|
58
58
|
rescue LoadError
|
|
59
59
|
end
|
|
60
60
|
when /\.(so|o|sl)$/
|
|
61
|
-
return
|
|
61
|
+
return require(file_name)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
begin
|
|
65
65
|
irb_load(f = file_name + ".rb")
|
|
66
66
|
$".push f
|
|
67
|
-
|
|
67
|
+
true
|
|
68
68
|
rescue LoadError
|
|
69
|
-
|
|
69
|
+
require(file_name)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
end
|
data/lib/irb/command/ls.rb
CHANGED
|
@@ -55,11 +55,13 @@ module IRB
|
|
|
55
55
|
|
|
56
56
|
o = Output.new(grep: grep)
|
|
57
57
|
|
|
58
|
-
klass
|
|
58
|
+
klass = Kernel.instance_method(:class).bind(obj).call
|
|
59
|
+
obj_is_class_or_module = Module === obj
|
|
60
|
+
klass = obj_is_class_or_module ? obj : klass
|
|
59
61
|
|
|
60
|
-
o.dump("constants", obj.constants) if
|
|
62
|
+
o.dump("constants", obj.constants) if obj_is_class_or_module
|
|
61
63
|
dump_methods(o, klass, obj)
|
|
62
|
-
o.dump("instance variables",
|
|
64
|
+
o.dump("instance variables", Kernel.instance_method(:instance_variables).bind(obj).call)
|
|
63
65
|
o.dump("class variables", klass.class_variables)
|
|
64
66
|
o.dump("locals", locals) if locals
|
|
65
67
|
o.print_result
|
|
@@ -67,7 +69,7 @@ module IRB
|
|
|
67
69
|
end
|
|
68
70
|
|
|
69
71
|
def dump_methods(o, klass, obj)
|
|
70
|
-
singleton_class = begin obj.
|
|
72
|
+
singleton_class = begin Kernel.instance_method(:singleton_class).bind(obj).call; rescue TypeError; nil end
|
|
71
73
|
dumped_mods = Array.new
|
|
72
74
|
ancestors = klass.ancestors
|
|
73
75
|
ancestors = ancestors.reject { |c| c >= Object } if klass < Object
|
data/lib/irb/command/measure.rb
CHANGED
|
@@ -35,13 +35,19 @@ module IRB
|
|
|
35
35
|
end
|
|
36
36
|
when :on
|
|
37
37
|
added = IRB.set_measure_callback(arg)
|
|
38
|
-
|
|
38
|
+
display_added_message(added[0]) if added
|
|
39
39
|
else
|
|
40
40
|
added = IRB.set_measure_callback(type, arg)
|
|
41
|
-
|
|
41
|
+
display_added_message(added[0]) if added
|
|
42
42
|
end
|
|
43
43
|
nil
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def display_added_message(added)
|
|
49
|
+
puts "#{added} is added."
|
|
50
|
+
end
|
|
45
51
|
end
|
|
46
52
|
end
|
|
47
53
|
|
data/lib/irb/command/pushws.rb
CHANGED
|
@@ -15,20 +15,26 @@ module IRB
|
|
|
15
15
|
description "Show workspaces."
|
|
16
16
|
|
|
17
17
|
def execute(_arg)
|
|
18
|
-
|
|
18
|
+
inspection_results = irb_context.instance_variable_get(:@workspace_stack).map do |ws|
|
|
19
19
|
truncated_inspect(ws.main)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
puts "[" +
|
|
22
|
+
puts "[" + inspection_results.join(", ") + "]"
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
private
|
|
26
26
|
|
|
27
27
|
def truncated_inspect(obj)
|
|
28
|
+
threshold = 20
|
|
28
29
|
obj_inspection = obj.inspect
|
|
29
30
|
|
|
30
|
-
if obj_inspection.size >
|
|
31
|
-
|
|
31
|
+
if obj_inspection.size > threshold
|
|
32
|
+
closing = obj_inspection[-1]
|
|
33
|
+
# Support closing characters for objects like:
|
|
34
|
+
# #<Object...>, [array...], {hash...}, (123/456...), "string...", /regexp.../
|
|
35
|
+
# Other objects will be truncated without a closing character.
|
|
36
|
+
closing = nil unless '>]})"/'.include?(closing)
|
|
37
|
+
obj_inspection = "#{obj_inspection[...threshold - 1]}...#{closing}"
|
|
32
38
|
end
|
|
33
39
|
|
|
34
40
|
obj_inspection
|
data/lib/irb/completion.rb
CHANGED
|
@@ -8,6 +8,29 @@
|
|
|
8
8
|
require_relative 'ruby-lex'
|
|
9
9
|
|
|
10
10
|
module IRB
|
|
11
|
+
class DocumentTarget # :nodoc:
|
|
12
|
+
attr_reader :name
|
|
13
|
+
|
|
14
|
+
def initialize(name)
|
|
15
|
+
@name = name
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class CommandDocument < DocumentTarget # :nodoc:
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Represents a method/class documentation target. May hold multiple names
|
|
23
|
+
# when the receiver is ambiguous (e.g. `{}.any?` could be Hash#any? or Proc#any?).
|
|
24
|
+
# The dialog popup uses only the first name; the full-screen display renders all.
|
|
25
|
+
class MethodDocument < DocumentTarget # :nodoc:
|
|
26
|
+
attr_reader :names
|
|
27
|
+
|
|
28
|
+
def initialize(*names)
|
|
29
|
+
super(names.first)
|
|
30
|
+
@names = names
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
11
34
|
class BaseCompletor # :nodoc:
|
|
12
35
|
|
|
13
36
|
# Set of reserved words used by Ruby, you should not use these for
|
|
@@ -76,6 +99,12 @@ module IRB
|
|
|
76
99
|
end
|
|
77
100
|
end
|
|
78
101
|
|
|
102
|
+
def command_document_target(preposing, matched)
|
|
103
|
+
if preposing.empty? && IRB::Command.command_names.include?(matched)
|
|
104
|
+
CommandDocument.new(matched)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
79
108
|
def retrieve_files_to_require_relative_from_current_dir
|
|
80
109
|
@files_from_current_dir ||= Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: '.').map { |path|
|
|
81
110
|
path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
|
|
@@ -118,8 +147,10 @@ module IRB
|
|
|
118
147
|
end
|
|
119
148
|
|
|
120
149
|
def doc_namespace(preposing, matched, _postposing, bind:)
|
|
121
|
-
|
|
122
|
-
|
|
150
|
+
command_document_target(preposing, matched) || begin
|
|
151
|
+
result = ReplTypeCompletor.analyze(preposing + matched, binding: bind, filename: @context.irb_path)
|
|
152
|
+
result&.doc_namespace('')
|
|
153
|
+
end
|
|
123
154
|
end
|
|
124
155
|
end
|
|
125
156
|
|
|
@@ -166,22 +197,13 @@ module IRB
|
|
|
166
197
|
else
|
|
167
198
|
return nil # It's not String literal
|
|
168
199
|
end
|
|
169
|
-
tokens = RubyLex.ripper_lex_without_warning(preposing.rstrip)
|
|
170
|
-
tok = nil
|
|
171
|
-
tokens.reverse_each do |t|
|
|
172
|
-
unless [:on_lparen, :on_sp, :on_ignored_sp, :on_nl, :on_ignored_nl, :on_comment].include?(t.event)
|
|
173
|
-
tok = t
|
|
174
|
-
break
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
return unless tok&.event == :on_ident && tok.state == Ripper::EXPR_CMDARG
|
|
178
200
|
|
|
179
|
-
case
|
|
180
|
-
when
|
|
201
|
+
case preposing
|
|
202
|
+
when /(^|[^\w])require\(? *\z/
|
|
181
203
|
retrieve_files_to_require_from_load_path.filter_map { |path|
|
|
182
204
|
quote + path if path.start_with?(actual_target)
|
|
183
205
|
}
|
|
184
|
-
when
|
|
206
|
+
when /(^|[^\w])require_relative\(? *\z/
|
|
185
207
|
retrieve_files_to_require_relative_from_current_dir.filter_map { |path|
|
|
186
208
|
quote + path if path.start_with?(actual_target)
|
|
187
209
|
}
|
|
@@ -210,8 +232,8 @@ module IRB
|
|
|
210
232
|
commands | completion_data
|
|
211
233
|
end
|
|
212
234
|
|
|
213
|
-
def doc_namespace(
|
|
214
|
-
retrieve_completion_data(matched, bind: bind, doc_namespace: true)
|
|
235
|
+
def doc_namespace(preposing, matched, _postposing, bind:)
|
|
236
|
+
command_document_target(preposing, matched) || retrieve_completion_data(matched, bind: bind, doc_namespace: true)
|
|
215
237
|
end
|
|
216
238
|
|
|
217
239
|
def retrieve_completion_data(input, bind:, doc_namespace:)
|
|
@@ -280,7 +302,7 @@ module IRB
|
|
|
280
302
|
rescue EncodingError
|
|
281
303
|
# ignore
|
|
282
304
|
end
|
|
283
|
-
candidates.grep(/^#{Regexp.quote(sym)}/)
|
|
305
|
+
candidates.grep(/^#{Regexp.quote(sym)}/).sort
|
|
284
306
|
end
|
|
285
307
|
when /^::([A-Z][^:\.\(\)]*)$/
|
|
286
308
|
# Absolute Constant or class methods
|
|
@@ -291,7 +313,7 @@ module IRB
|
|
|
291
313
|
if doc_namespace
|
|
292
314
|
candidates.find { |i| i == receiver }
|
|
293
315
|
else
|
|
294
|
-
candidates.grep(/^#{Regexp.quote(receiver)}/).collect{|e| "::" + e}
|
|
316
|
+
candidates.grep(/^#{Regexp.quote(receiver)}/).sort.collect{|e| "::" + e}
|
|
295
317
|
end
|
|
296
318
|
|
|
297
319
|
when /^([A-Z].*)::([^:.]*)$/
|
|
@@ -309,7 +331,7 @@ module IRB
|
|
|
309
331
|
candidates = []
|
|
310
332
|
end
|
|
311
333
|
|
|
312
|
-
select_message(receiver, message, candidates
|
|
334
|
+
select_message(receiver, message, candidates, "::")
|
|
313
335
|
end
|
|
314
336
|
|
|
315
337
|
when /^(:[^:.]+)(\.|::)([^.]*)$/
|
|
@@ -378,7 +400,7 @@ module IRB
|
|
|
378
400
|
if doc_namespace
|
|
379
401
|
all_gvars.find{ |i| i == gvar }
|
|
380
402
|
else
|
|
381
|
-
all_gvars.grep(Regexp.new(Regexp.quote(gvar)))
|
|
403
|
+
all_gvars.grep(Regexp.new(Regexp.quote(gvar))).sort
|
|
382
404
|
end
|
|
383
405
|
|
|
384
406
|
when /^([^.:"].*)(\.|::)([^.]*)$/
|
|
@@ -430,7 +452,7 @@ module IRB
|
|
|
430
452
|
if doc_namespace
|
|
431
453
|
"String.#{candidates.find{ |i| i == message }}"
|
|
432
454
|
else
|
|
433
|
-
select_message(receiver, message, candidates
|
|
455
|
+
select_message(receiver, message, candidates)
|
|
434
456
|
end
|
|
435
457
|
when /^\s*$/
|
|
436
458
|
# empty input
|
|
@@ -469,7 +491,11 @@ module IRB
|
|
|
469
491
|
Operators = %w[% & * ** + - / < << <= <=> == === =~ > >= >> [] []= ^ ! != !~]
|
|
470
492
|
|
|
471
493
|
def select_message(receiver, message, candidates, sep = ".")
|
|
472
|
-
candidates.grep(/^#{Regexp.quote(message)}/).
|
|
494
|
+
sorted_candidates = candidates.grep(/^#{Regexp.quote(message)}/).sort_by do |e|
|
|
495
|
+
# Alphabetical order, but internal methods (leading underscore) last
|
|
496
|
+
[e.start_with?('_') ? 1 : 0, e]
|
|
497
|
+
end
|
|
498
|
+
sorted_candidates.collect do |e|
|
|
473
499
|
case e
|
|
474
500
|
when /^[a-zA-Z_]/
|
|
475
501
|
receiver + sep + e
|
data/lib/irb/context.rb
CHANGED
|
@@ -475,8 +475,8 @@ module IRB
|
|
|
475
475
|
@prompt_c = pconf[:PROMPT_C]
|
|
476
476
|
@return_format = pconf[:RETURN]
|
|
477
477
|
@return_format = "%s\n" if @return_format == nil
|
|
478
|
-
if
|
|
479
|
-
@auto_indent_mode =
|
|
478
|
+
if pconf.include?(:AUTO_INDENT)
|
|
479
|
+
@auto_indent_mode = pconf[:AUTO_INDENT]
|
|
480
480
|
else
|
|
481
481
|
@auto_indent_mode = IRB.conf[:AUTO_INDENT]
|
|
482
482
|
end
|
data/lib/irb/ext/eval_history.rb
CHANGED
|
@@ -50,7 +50,7 @@ module IRB # :nodoc:
|
|
|
50
50
|
@eval_history_values = EvalHistory.new(no)
|
|
51
51
|
IRB.conf[:__TMP__EHV__] = @eval_history_values
|
|
52
52
|
workspace.evaluate("__ = IRB.conf[:__TMP__EHV__]")
|
|
53
|
-
IRB.conf.delete(:
|
|
53
|
+
IRB.conf.delete(:__TMP__EHV__)
|
|
54
54
|
end
|
|
55
55
|
else
|
|
56
56
|
@eval_history_values = nil
|
|
@@ -97,8 +97,8 @@ module IRB # :nodoc:
|
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
def size(size) # :nodoc:
|
|
100
|
-
if size
|
|
101
|
-
@contents = @contents
|
|
100
|
+
if size.positive? && @contents.size > size
|
|
101
|
+
@contents = @contents.last(size)
|
|
102
102
|
end
|
|
103
103
|
@size = size
|
|
104
104
|
end
|
data/lib/irb/ext/loader.rb
CHANGED
|
@@ -13,9 +13,6 @@ module IRB # :nodoc:
|
|
|
13
13
|
# See ExtendCommandBundle for more information.
|
|
14
14
|
module IrbLoader
|
|
15
15
|
|
|
16
|
-
alias ruby_load load
|
|
17
|
-
alias ruby_require require
|
|
18
|
-
|
|
19
16
|
# Loads the given file similarly to Kernel#load
|
|
20
17
|
def irb_load(fn, priv = nil)
|
|
21
18
|
path = search_file_from_ruby_path(fn)
|
data/lib/irb/history.rb
CHANGED
|
@@ -64,13 +64,6 @@ module IRB
|
|
|
64
64
|
def save_history
|
|
65
65
|
return unless History.save_history?
|
|
66
66
|
return unless (history_file = History.history_file)
|
|
67
|
-
unless ensure_history_file_writable(history_file)
|
|
68
|
-
warn <<~WARN
|
|
69
|
-
Can't write history to #{History.history_file.inspect} due to insufficient permissions.
|
|
70
|
-
Please verify the value of `IRB.conf[:HISTORY_FILE]`. Ensure the folder exists and that both the folder and file (if it exists) are writable.
|
|
71
|
-
WARN
|
|
72
|
-
return
|
|
73
|
-
end
|
|
74
67
|
|
|
75
68
|
history = self.class::HISTORY.to_a
|
|
76
69
|
|
|
@@ -80,36 +73,43 @@ module IRB
|
|
|
80
73
|
append_history = true
|
|
81
74
|
end
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
begin
|
|
77
|
+
ensure_history_file_permissions(history_file)
|
|
85
78
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
File.open(history_file, (append_history ? "a" : "w"), 0o600, encoding: IRB.conf[:LC_MESSAGES]&.encoding) do |f|
|
|
80
|
+
hist = history.map { |l| l.scrub.split("\n").join("\\\n") }
|
|
81
|
+
|
|
82
|
+
unless append_history || History.infinite?
|
|
83
|
+
# Check size before slicing because array.last(huge_number) raises RangeError.
|
|
84
|
+
hist = hist.last(History.save_history) if hist.size > History.save_history
|
|
85
|
+
end
|
|
90
86
|
|
|
91
|
-
|
|
87
|
+
f.puts(hist)
|
|
88
|
+
end
|
|
89
|
+
rescue Errno::ENOENT
|
|
90
|
+
warn <<~WARN
|
|
91
|
+
Can't write history to #{History.history_file.inspect} because the folder does not exist.
|
|
92
|
+
Please verify the value of `IRB.conf[:HISTORY_FILE]`. Ensure the folder exists.
|
|
93
|
+
WARN
|
|
94
|
+
rescue Errno::EACCES, Errno::EPERM
|
|
95
|
+
warn <<~WARN
|
|
96
|
+
Can't write history to #{History.history_file.inspect} due to insufficient permissions.
|
|
97
|
+
Please verify the value of `IRB.conf[:HISTORY_FILE]`. Ensure the folder exists and that both the folder and file (if it exists) are writable.
|
|
98
|
+
WARN
|
|
92
99
|
end
|
|
93
100
|
end
|
|
94
101
|
|
|
95
102
|
private
|
|
96
103
|
|
|
97
|
-
# Returns boolean whether writing to +history_file+ will be possible.
|
|
98
104
|
# Permissions of already existing +history_file+ are changed to
|
|
99
105
|
# owner-only-readable if necessary [BUG #7694].
|
|
100
|
-
def
|
|
106
|
+
def ensure_history_file_permissions(history_file)
|
|
101
107
|
history_file = Pathname.new(history_file)
|
|
102
108
|
|
|
103
|
-
return
|
|
104
|
-
return true unless history_file.exist?
|
|
109
|
+
return unless history_file.exist?
|
|
105
110
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
history_file.chmod 0o600
|
|
109
|
-
end
|
|
110
|
-
true
|
|
111
|
-
rescue Errno::EPERM # no permissions
|
|
112
|
-
false
|
|
111
|
+
if history_file.stat.mode & 0o66 != 0
|
|
112
|
+
history_file.chmod 0o600
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
end
|
data/lib/irb/init.rb
CHANGED
|
@@ -87,6 +87,7 @@ module IRB # :nodoc:
|
|
|
87
87
|
@CONF[:IGNORE_SIGINT] = true
|
|
88
88
|
@CONF[:IGNORE_EOF] = false
|
|
89
89
|
@CONF[:USE_PAGER] = true
|
|
90
|
+
@CONF[:SHOW_BANNER] = true
|
|
90
91
|
@CONF[:EXTRA_DOC_DIRS] = []
|
|
91
92
|
@CONF[:ECHO] = nil
|
|
92
93
|
@CONF[:ECHO_ON_ASSIGNMENT] = nil
|
|
@@ -147,9 +148,12 @@ module IRB # :nodoc:
|
|
|
147
148
|
@CONF[:MEASURE_PROC] = {}
|
|
148
149
|
@CONF[:MEASURE_PROC][:TIME] = proc { |context, code, line_no, &block|
|
|
149
150
|
time = Time.now
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
begin
|
|
152
|
+
result = block.()
|
|
153
|
+
ensure
|
|
154
|
+
now = Time.now
|
|
155
|
+
puts 'processing time: %fs' % (now - time) if IRB.conf[:MEASURE]
|
|
156
|
+
end
|
|
153
157
|
result
|
|
154
158
|
}
|
|
155
159
|
# arg can be either a symbol for the mode (:cpu, :wall, ..) or a hash for
|
|
@@ -345,6 +349,8 @@ module IRB # :nodoc:
|
|
|
345
349
|
opt = $1 || argv.shift
|
|
346
350
|
prompt_mode = opt.upcase.tr("-", "_").intern
|
|
347
351
|
@CONF[:PROMPT_MODE] = prompt_mode
|
|
352
|
+
when "--nobanner"
|
|
353
|
+
@CONF[:SHOW_BANNER] = false
|
|
348
354
|
when "--noprompt"
|
|
349
355
|
@CONF[:PROMPT_MODE] = :NULL
|
|
350
356
|
when "--script"
|