irb 1.11.1 → 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17969636013c03ffd08d5b53570ec0eda8620855092bd863c5b851e668343007
4
- data.tar.gz: 7900a886588ebca5839e2b6fac6d538e58febd2706cdbbe979e098f2950d2d79
3
+ metadata.gz: 53ffdc8550a2c9debc40dc6565f23010c02959bf924fc917a6736465960dc660
4
+ data.tar.gz: ca6f06898a6b431303c5b63b9f8ff88295106ad66d8cb30e85a6f5f879449c8e
5
5
  SHA512:
6
- metadata.gz: e9d8fe7568718ce10db38ed1a85ad92473c21ca81738cadaa8a8258adcf18cdbfc5755c61621c336ac4bc53c57a08ad26311a4fc671fb98ad0cd5130c2e7527e
7
- data.tar.gz: 729f6a0f6ba9fe6cfac3e2ed9e752531006f60c386b3e51fd84c877eeb1b3cdcb0fee1a7bf44c3c0bfa7f0f56def8ad8c7d99413b9b96b304d17e0c15d90aa87
6
+ metadata.gz: '059eb872f0be29fec2c8fe7c64b809f9346b3e25b084a1033ab4ea6e02e7c3e311317d2a169a18d5a9291acc578e56c1587c12f901d2e09fa52d58fe3717377c'
7
+ data.tar.gz: 8b6cce5c6bc85f25db7a78977e433746efa47d2eb0b0828d9adebb813ce0648396aae6e0c903aca30b79f2c1e947f319e75b21e916eb6f8a8a8f8d5553431d5c
data/Gemfile CHANGED
@@ -17,6 +17,9 @@ gem "rake"
17
17
  gem "test-unit"
18
18
  gem "test-unit-ruby-core"
19
19
 
20
+ gem "rubocop"
21
+
22
+ gem "tracer" if !is_truffleruby
20
23
  gem "debug", github: "ruby/debug", platforms: [:mri, :mswin]
21
24
 
22
25
  if RUBY_VERSION >= "3.0.0" && !is_truffleruby
data/README.md CHANGED
@@ -384,7 +384,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/i
384
384
 
385
385
  ### Run integration tests
386
386
 
387
- If your changes affect component rendering, such as the autocompletion's dialog/dropdown, you may need to run IRB's integration tests, known as `yamatanarroroti`.
387
+ If your changes affect component rendering, such as the autocompletion's dialog/dropdown, you may need to run IRB's integration tests, known as `yamatanooroti`.
388
388
 
389
389
  Before running these tests, ensure that you have `libvterm` installed. If you're using Homebrew, you can install it by running:
390
390
 
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ task :test_in_isolation do
17
17
  ENV["TEST"] = test_file
18
18
  begin
19
19
  Rake::Task["test"].execute
20
- rescue => e
20
+ rescue
21
21
  failed = true
22
22
  msg = "Test '#{test_file}' failed when being executed in isolation. Please make sure 'rake test TEST=#{test_file}' passes."
23
23
  separation_line = '=' * msg.length
data/lib/irb/context.rb CHANGED
@@ -61,7 +61,7 @@ module IRB
61
61
  @io = nil
62
62
 
63
63
  self.inspect_mode = IRB.conf[:INSPECT_MODE]
64
- self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
64
+ self.use_tracer = IRB.conf[:USE_TRACER]
65
65
  self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
66
66
  self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY]
67
67
 
@@ -161,6 +161,11 @@ module IRB
161
161
 
162
162
  private_constant :KEYWORD_ALIASES
163
163
 
164
+ def use_tracer=(val)
165
+ require_relative "ext/tracer" if val
166
+ IRB.conf[:USE_TRACER] = val
167
+ end
168
+
164
169
  private def build_completor
165
170
  completor_type = IRB.conf[:COMPLETOR]
166
171
  case completor_type
@@ -178,7 +183,7 @@ module IRB
178
183
 
179
184
  private def build_type_completor
180
185
  if RUBY_ENGINE == 'truffleruby'
181
- # Avoid SynatxError. truffleruby does not support endless method definition yet.
186
+ # Avoid SyntaxError. truffleruby does not support endless method definition yet.
182
187
  warn 'TypeCompletor is not supported on TruffleRuby yet'
183
188
  return
184
189
  end
@@ -3,76 +3,37 @@
3
3
  # irb/lib/tracer.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
5
  #
6
-
6
+ # Loading the gem "tracer" will cause it to extend IRB commands with:
7
+ # https://github.com/ruby/tracer/blob/v0.2.2/lib/tracer/irb.rb
7
8
  begin
8
9
  require "tracer"
9
10
  rescue LoadError
10
11
  $stderr.puts "Tracer extension of IRB is enabled but tracer gem wasn't found."
11
- module IRB
12
- class Context
13
- def use_tracer=(opt)
14
- # do nothing
15
- end
16
- end
17
- end
18
12
  return # This is about to disable loading below
19
13
  end
20
14
 
21
15
  module IRB
16
+ class CallTracer < ::CallTracer
17
+ IRB_DIR = File.expand_path('../..', __dir__)
22
18
 
23
- # initialize tracing function
24
- def IRB.initialize_tracer
25
- Tracer.verbose = false
26
- Tracer.add_filter {
27
- |event, file, line, id, binding, *rests|
28
- /^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
29
- File::basename(file) != "irb.rb"
30
- }
31
- end
32
-
33
- class Context
34
- # Whether Tracer is used when evaluating statements in this context.
35
- #
36
- # See +lib/tracer.rb+ for more information.
37
- attr_reader :use_tracer
38
- alias use_tracer? use_tracer
39
-
40
- # Sets whether or not to use the Tracer library when evaluating statements
41
- # in this context.
42
- #
43
- # See +lib/tracer.rb+ for more information.
44
- def use_tracer=(opt)
45
- if opt
46
- Tracer.set_get_line_procs(@irb_path) {
47
- |line_no, *rests|
48
- @io.line(line_no)
49
- }
50
- elsif !opt && @use_tracer
51
- Tracer.off
52
- end
53
- @use_tracer=opt
19
+ def skip?(tp)
20
+ super || tp.path.match?(IRB_DIR) || tp.path.match?('<internal:prelude>')
54
21
  end
55
22
  end
56
-
57
23
  class WorkSpace
58
24
  alias __evaluate__ evaluate
59
25
  # Evaluate the context of this workspace and use the Tracer library to
60
26
  # output the exact lines of code are being executed in chronological order.
61
27
  #
62
- # See +lib/tracer.rb+ for more information.
63
- def evaluate(context, statements, file = nil, line = nil)
64
- if context.use_tracer? && file != nil && line != nil
65
- Tracer.on
66
- begin
28
+ # See https://github.com/ruby/tracer for more information.
29
+ def evaluate(statements, file = __FILE__, line = __LINE__)
30
+ if IRB.conf[:USE_TRACER] == true
31
+ CallTracer.new(colorize: Color.colorable?).start do
67
32
  __evaluate__(statements, file, line)
68
- ensure
69
- Tracer.off
70
33
  end
71
34
  else
72
- __evaluate__(statements, file || __FILE__, line || __LINE__)
35
+ __evaluate__(statements, file, line)
73
36
  end
74
37
  end
75
38
  end
76
-
77
- IRB.initialize_tracer
78
39
  end
@@ -317,7 +317,6 @@ module IRB # :nodoc:
317
317
 
318
318
  @EXTEND_COMMANDS = [
319
319
  [:eval_history=, "ext/eval_history.rb"],
320
- [:use_tracer=, "ext/tracer.rb"],
321
320
  [:use_loader=, "ext/use-loader.rb"],
322
321
  ]
323
322
 
data/lib/irb/history.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "pathname"
2
+
1
3
  module IRB
2
4
  module HistorySavingAbility # :nodoc:
3
5
  def support_history_saving?
@@ -5,7 +7,7 @@ module IRB
5
7
  end
6
8
 
7
9
  def reset_history_counter
8
- @loaded_history_lines = self.class::HISTORY.size if defined? @loaded_history_lines
10
+ @loaded_history_lines = self.class::HISTORY.size
9
11
  end
10
12
 
11
13
  def load_history
@@ -59,13 +61,19 @@ module IRB
59
61
  append_history = true
60
62
  end
61
63
 
64
+ pathname = Pathname.new(history_file)
65
+ unless Dir.exist?(pathname.dirname)
66
+ warn "Warning: The directory to save IRB's history file does not exist. Please double check `IRB.conf[:HISTORY_FILE]`'s value."
67
+ return
68
+ end
69
+
62
70
  File.open(history_file, (append_history ? 'a' : 'w'), 0o600, encoding: IRB.conf[:LC_MESSAGES]&.encoding) do |f|
63
71
  hist = history.map{ |l| l.scrub.split("\n").join("\\\n") }
64
72
  unless append_history
65
73
  begin
66
74
  hist = hist.last(num) if hist.size > num and num > 0
67
75
  rescue RangeError # bignum too big to convert into `long'
68
- # Do nothing because the bignum should be treated as inifinity
76
+ # Do nothing because the bignum should be treated as infinity
69
77
  end
70
78
  end
71
79
  f.puts(hist)
data/lib/irb/init.rb CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  module IRB # :nodoc:
8
8
  @CONF = {}
9
+ @INITIALIZED = false
9
10
  # Displays current configuration.
10
11
  #
11
12
  # Modifying the configuration is achieved by sending a message to IRB.conf.
@@ -41,6 +42,10 @@ module IRB # :nodoc:
41
42
  format("irb %s (%s)", @RELEASE_VERSION, @LAST_UPDATE_DATE)
42
43
  end
43
44
 
45
+ def IRB.initialized?
46
+ !!@INITIALIZED
47
+ end
48
+
44
49
  # initialize config
45
50
  def IRB.setup(ap_path, argv: ::ARGV)
46
51
  IRB.init_config(ap_path)
@@ -52,13 +57,11 @@ module IRB # :nodoc:
52
57
  unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
53
58
  fail UndefinedPromptMode, @CONF[:PROMPT_MODE]
54
59
  end
60
+ @INITIALIZED = true
55
61
  end
56
62
 
57
63
  # @CONF default setting
58
64
  def IRB.init_config(ap_path)
59
- # class instance variables
60
- @TRACER_INITIALIZED = false
61
-
62
65
  # default configurations
63
66
  unless ap_path and @CONF[:AP_NAME]
64
67
  ap_path = File.join(File.dirname(File.dirname(__FILE__)), "irb.rb")
data/lib/irb/inspector.rb CHANGED
@@ -46,7 +46,7 @@ module IRB # :nodoc:
46
46
  # Determines the inspector to use where +inspector+ is one of the keys passed
47
47
  # during inspector definition.
48
48
  def self.keys_with_inspector(inspector)
49
- INSPECTORS.select{|k,v| v == inspector}.collect{|k, v| k}
49
+ INSPECTORS.select{|k, v| v == inspector}.collect{|k, v| k}
50
50
  end
51
51
 
52
52
  # Example
data/lib/irb/locale.rb CHANGED
@@ -94,7 +94,7 @@ module IRB # :nodoc:
94
94
  end
95
95
  end
96
96
 
97
- def find(file , paths = $:)
97
+ def find(file, paths = $:)
98
98
  dir = File.dirname(file)
99
99
  dir = "" if dir == "."
100
100
  base = File.basename(file)
@@ -12,6 +12,8 @@ module IRB
12
12
  skip = false
13
13
  last_tok, state, args = opens.last
14
14
  case state
15
+ when :in_alias_undef
16
+ skip = t.event == :on_kw
15
17
  when :in_unquoted_symbol
16
18
  unless IGNORE_TOKENS.include?(t.event)
17
19
  opens.pop
@@ -61,17 +63,17 @@ module IRB
61
63
  if args.include?(:arg)
62
64
  case t.event
63
65
  when :on_nl, :on_semicolon
64
- # def recever.f;
66
+ # def receiver.f;
65
67
  body = :normal
66
68
  when :on_lparen
67
- # def recever.f()
69
+ # def receiver.f()
68
70
  next_args << :eq
69
71
  else
70
72
  if t.event == :on_op && t.tok == '='
71
73
  # def receiver.f =
72
74
  body = :oneliner
73
75
  else
74
- # def recever.f arg
76
+ # def receiver.f arg
75
77
  next_args << :arg_without_paren
76
78
  end
77
79
  end
@@ -130,6 +132,10 @@ module IRB
130
132
  opens.pop
131
133
  opens << [t, nil]
132
134
  end
135
+ when 'alias'
136
+ opens << [t, :in_alias_undef, 2]
137
+ when 'undef'
138
+ opens << [t, :in_alias_undef, 1]
133
139
  when 'elsif', 'else', 'when'
134
140
  opens.pop
135
141
  opens << [t, nil]
@@ -174,6 +180,10 @@ module IRB
174
180
  pending_heredocs.reverse_each { |t| opens << [t, nil] }
175
181
  pending_heredocs = []
176
182
  end
183
+ if opens.last && opens.last[1] == :in_alias_undef && !IGNORE_TOKENS.include?(t.event) && t.event != :on_heredoc_end
184
+ tok, state, arg = opens.pop
185
+ opens << [tok, state, arg - 1] if arg >= 1
186
+ end
177
187
  yield t, opens if block_given?
178
188
  end
179
189
  opens.map(&:first) + pending_heredocs.reverse
data/lib/irb/ruby-lex.rb CHANGED
@@ -290,7 +290,7 @@ module IRB
290
290
  when :on_embdoc_beg
291
291
  indent_level = 0
292
292
  else
293
- indent_level += 1
293
+ indent_level += 1 unless t.tok == 'alias' || t.tok == 'undef'
294
294
  end
295
295
  end
296
296
  indent_level
data/lib/irb/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module IRB # :nodoc:
8
- VERSION = "1.11.1"
8
+ VERSION = "1.11.2"
9
9
  @RELEASE_VERSION = VERSION
10
- @LAST_UPDATE_DATE = "2024-01-08"
10
+ @LAST_UPDATE_DATE = "2024-02-07"
11
11
  end
data/lib/irb.rb CHANGED
@@ -203,11 +203,10 @@ require_relative "irb/pager"
203
203
  #
204
204
  # === Input Command History
205
205
  #
206
- # By default, \IRB stores a history of up to 1000 input commands
207
- # in file <tt>~/.irb_history</tt>
208
- # (or, if a {configuration file}[rdoc-ref:IRB@Configuration+File]
209
- # is found, in file +.irb_history+
210
- # inin the same directory as that file).
206
+ # By default, \IRB stores a history of up to 1000 input commands in a
207
+ # file named <tt>.irb_history</tt>. The history file will be in the same directory
208
+ # as the {configuration file}[rdoc-ref:IRB@Configuration+File] if one is found, or
209
+ # in <tt>~/</tt> otherwise.
211
210
  #
212
211
  # A new \IRB session creates the history file if it does not exist,
213
212
  # and appends to the file if it does exist.
@@ -365,7 +364,7 @@ require_relative "irb/pager"
365
364
  # You can change the initial behavior and suppress all echoing by:
366
365
  #
367
366
  # - Adding to the configuration file: <tt>IRB.conf[:ECHO] = false</tt>.
368
- # (The default value for this entry is +niL+, which means the same as +true+.)
367
+ # (The default value for this entry is +nil+, which means the same as +true+.)
369
368
  # - Giving command-line option <tt>--noecho</tt>.
370
369
  # (The default is <tt>--echo</tt>.)
371
370
  #
@@ -392,7 +391,7 @@ require_relative "irb/pager"
392
391
  # (The default value for this entry is +niL+, which means the same as +:truncate+.)
393
392
  # - Giving command-line option <tt>--noecho-on-assignment</tt>
394
393
  # or <tt>--echo-on-assignment</tt>.
395
- # (The default is <tt>--truncate-echo-on-assigment</tt>.)
394
+ # (The default is <tt>--truncate-echo-on-assignment</tt>.)
396
395
  #
397
396
  # During the session, you can change the current setting
398
397
  # with configuration method <tt>conf.echo_on_assignment=</tt>
@@ -413,7 +412,7 @@ require_relative "irb/pager"
413
412
  #
414
413
  # By default, \IRB prefixes a newline to a multiline response.
415
414
  #
416
- # You can change the initial default value by adding to the configuation file:
415
+ # You can change the initial default value by adding to the configuration file:
417
416
  #
418
417
  # IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT] = false
419
418
  #
@@ -945,7 +944,7 @@ module IRB
945
944
  # Irb#eval_input will simply return the input, and we need to pass it to the debugger.
946
945
  input = if IRB.conf[:SAVE_HISTORY] && context.io.support_history_saving?
947
946
  # Previous IRB session's history has been saved when `Irb#run` is exited
948
- # We need to make sure the saved history is not saved again by reseting the counter
947
+ # We need to make sure the saved history is not saved again by resetting the counter
949
948
  context.io.reset_history_counter
950
949
 
951
950
  begin
@@ -1515,7 +1514,7 @@ class Binding
1515
1514
  # See IRB for more information.
1516
1515
  def irb(show_code: true)
1517
1516
  # Setup IRB with the current file's path and no command line arguments
1518
- IRB.setup(source_location[0], argv: [])
1517
+ IRB.setup(source_location[0], argv: []) unless IRB.initialized?
1519
1518
  # Create a new workspace using the current binding
1520
1519
  workspace = IRB::WorkSpace.new(self)
1521
1520
  # Print the code around the binding if show_code is true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 1.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-01-09 00:00:00.000000000 Z
12
+ date: 2024-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: reline