irb 1.13.2 → 1.14.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 243737997cdd6abe7e129eb7e7945dca379f1af38ed4254dfe094f2a611918cc
4
- data.tar.gz: 5a1cbbdf5ab88a61278afe32a5497f38efa1342e123734ae3ede6135aae9b91f
3
+ metadata.gz: b96add3ef12d981b483ae225bfd8bca8a1a477f0b03c8040a0dfbf047bd0d1fb
4
+ data.tar.gz: efe91e97fab6b11a239c4774da9d5ecfe39bbc364d61a6b2c7fd6ec8b9c01a72
5
5
  SHA512:
6
- metadata.gz: 0b4e5d658e1eba4a0503ffd3776c3baffabb0782eb43a993aac593b6dc4383e9e209ca3c1f077c78225f612a1ac7607f951bc11a2ff8fd78a93e12029fbf1954
7
- data.tar.gz: c9e978f318f22d322934b77b8c431830e67a9cb7cf365923041f77123ee5e7d39ffa814a4e7bdd9af759f4671d0b24bd2ae68a9d20beb54b4a0e4248e32ee85f
6
+ metadata.gz: 0eaa119e765d958cdab2ba80fa12e47a9727d389a37f255e174ec260279af8e2c2edb510689364541fe40f3c202a3b3d4f2d7dc7fbe30030b04e89bc2c851a3a
7
+ data.tar.gz: 71904280b978ac48763d7bc965f053fd5580ec7876c40cba76a1a9c26ac7aec2f4ad98deb1d9c8d3635f5222a0b757d458d7fded9264411b05f19bfe77ad2526
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Command
5
+ class CD < Base
6
+ category "Workspace"
7
+ description "Move into the given object or leave the current context."
8
+
9
+ help_message(<<~HELP)
10
+ Usage: cd ([target]|..)
11
+
12
+ IRB uses a stack of workspaces to keep track of context(s), with `pushws` and `popws` commands to manipulate the stack.
13
+ The `cd` command is an attempt to simplify the operation and will be subject to change.
14
+
15
+ When given:
16
+ - an object, cd will use that object as the new context by pushing it onto the workspace stack.
17
+ - "..", cd will leave the current context by popping the top workspace off the stack.
18
+ - no arguments, cd will move to the top workspace on the stack by popping off all workspaces.
19
+
20
+ Examples:
21
+
22
+ cd Foo
23
+ cd Foo.new
24
+ cd @ivar
25
+ cd ..
26
+ cd
27
+ HELP
28
+
29
+ def execute(arg)
30
+ case arg
31
+ when ".."
32
+ irb_context.pop_workspace
33
+ when ""
34
+ # TODO: decide what workspace commands should be kept, and underlying APIs should look like,
35
+ # and perhaps add a new API to clear the workspace stack.
36
+ prev_workspace = irb_context.pop_workspace
37
+ while prev_workspace
38
+ prev_workspace = irb_context.pop_workspace
39
+ end
40
+ else
41
+ begin
42
+ obj = eval(arg, irb_context.workspace.binding)
43
+ irb_context.push_workspace(obj)
44
+ rescue StandardError => e
45
+ warn "Error: #{e}"
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -33,6 +33,8 @@ module IRB
33
33
  yield
34
34
  ]
35
35
 
36
+ HELP_COMMAND_PREPOSING = /\Ahelp\s+/
37
+
36
38
  def completion_candidates(preposing, target, postposing, bind:)
37
39
  raise NotImplementedError
38
40
  end
@@ -86,8 +88,8 @@ module IRB
86
88
  )
87
89
  end
88
90
 
89
- def command_completions(preposing, target)
90
- if preposing.empty? && !target.empty?
91
+ def command_candidates(target)
92
+ if !target.empty?
91
93
  IRB::Command.command_names.select { _1.start_with?(target) }
92
94
  else
93
95
  []
@@ -111,8 +113,18 @@ module IRB
111
113
  end
112
114
 
113
115
  def completion_candidates(preposing, target, _postposing, bind:)
114
- commands = command_completions(preposing, target)
116
+ # When completing the argument of `help` command, only commands should be candidates
117
+ return command_candidates(target) if preposing.match?(HELP_COMMAND_PREPOSING)
118
+
119
+ commands = if preposing.empty?
120
+ command_candidates(target)
121
+ # It doesn't make sense to propose commands with other preposing
122
+ else
123
+ []
124
+ end
125
+
115
126
  result = ReplTypeCompletor.analyze(preposing + target, binding: bind, filename: @context.irb_path)
127
+
116
128
  return commands unless result
117
129
 
118
130
  commands | result.completion_candidates.map { target + _1 }
@@ -187,12 +199,20 @@ module IRB
187
199
  end
188
200
 
189
201
  def completion_candidates(preposing, target, postposing, bind:)
190
- if preposing && postposing
191
- result = complete_require_path(target, preposing, postposing)
192
- return result if result
202
+ if result = complete_require_path(target, preposing, postposing)
203
+ return result
193
204
  end
194
- commands = command_completions(preposing || '', target)
195
- commands | retrieve_completion_data(target, bind: bind, doc_namespace: false).compact.map{ |i| i.encode(Encoding.default_external) }
205
+
206
+ commands = command_candidates(target)
207
+
208
+ # When completing the argument of `help` command, only commands should be candidates
209
+ return commands if preposing.match?(HELP_COMMAND_PREPOSING)
210
+
211
+ # It doesn't make sense to propose commands with other preposing
212
+ commands = [] unless preposing.empty?
213
+
214
+ completion_data = retrieve_completion_data(target, bind: bind, doc_namespace: false).compact.map{ |i| i.encode(Encoding.default_external) }
215
+ commands | completion_data
196
216
  end
197
217
 
198
218
  def doc_namespace(_preposing, matched, _postposing, bind:)
@@ -470,7 +490,7 @@ module IRB
470
490
  end
471
491
  end
472
492
  CompletionProc = ->(target, preposing = nil, postposing = nil) {
473
- regexp_completor.completion_candidates(preposing, target, postposing, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding)
493
+ regexp_completor.completion_candidates(preposing || '', target, postposing || '', bind: IRB.conf[:MAIN_CONTEXT].workspace.binding)
474
494
  }
475
495
  end
476
496
  deprecate_constant :InputCompletor
data/lib/irb/context.rb CHANGED
@@ -602,7 +602,6 @@ module IRB
602
602
  set_last_value(result)
603
603
  when Statement::Command
604
604
  statement.command_class.execute(self, statement.arg)
605
- set_last_value(nil)
606
605
  end
607
606
 
608
607
  nil
@@ -5,6 +5,7 @@ require_relative "command/internal_helpers"
5
5
  require_relative "command/backtrace"
6
6
  require_relative "command/break"
7
7
  require_relative "command/catch"
8
+ require_relative "command/cd"
8
9
  require_relative "command/chws"
9
10
  require_relative "command/context"
10
11
  require_relative "command/continue"
@@ -240,6 +241,8 @@ module IRB
240
241
  _register_with_aliases(:irb_disable_irb, Command::DisableIrb,
241
242
  [:disable_irb, NO_OVERRIDE]
242
243
  )
244
+
245
+ register(:cd, Command::CD)
243
246
  end
244
247
 
245
248
  ExtendCommand = Command
data/lib/irb/statement.rb CHANGED
@@ -68,7 +68,7 @@ module IRB
68
68
  end
69
69
 
70
70
  def suppresses_echo?
71
- false
71
+ true
72
72
  end
73
73
 
74
74
  def should_be_handled_by_debugger?
data/lib/irb/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module IRB # :nodoc:
8
- VERSION = "1.13.2"
8
+ VERSION = "1.14.0"
9
9
  @RELEASE_VERSION = VERSION
10
- @LAST_UPDATE_DATE = "2024-06-15"
10
+ @LAST_UPDATE_DATE = "2024-07-06"
11
11
  end
data/lib/irb.rb CHANGED
@@ -1138,6 +1138,8 @@ module IRB
1138
1138
  end
1139
1139
  end
1140
1140
 
1141
+ ASSIGN_OPERATORS_REGEXP = Regexp.union(%w[= += -= *= /= %= **= &= |= &&= ||= ^= <<= >>=])
1142
+
1141
1143
  def parse_command(code)
1142
1144
  command_name, arg = code.strip.split(/\s+/, 2)
1143
1145
  return unless code.lines.size == 1 && command_name
@@ -1149,6 +1151,12 @@ module IRB
1149
1151
  return [alias_name, arg]
1150
1152
  end
1151
1153
 
1154
+ # Assignment-like expression is not a command
1155
+ return if arg.start_with?(ASSIGN_OPERATORS_REGEXP) && !arg.start_with?(/==|=~/)
1156
+
1157
+ # Local variable have precedence over command
1158
+ return if @context.local_variables.include?(command)
1159
+
1152
1160
  # Check visibility
1153
1161
  public_method = !!Kernel.instance_method(:public_method).bind_call(@context.main, command) rescue false
1154
1162
  private_method = !public_method && !!Kernel.instance_method(:method).bind_call(@context.main, command) rescue false
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.13.2
4
+ version: 1.14.0
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-06-15 00:00:00.000000000 Z
12
+ date: 2024-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: reline
@@ -68,6 +68,7 @@ files:
68
68
  - lib/irb/command/base.rb
69
69
  - lib/irb/command/break.rb
70
70
  - lib/irb/command/catch.rb
71
+ - lib/irb/command/cd.rb
71
72
  - lib/irb/command/chws.rb
72
73
  - lib/irb/command/context.rb
73
74
  - lib/irb/command/continue.rb