Skip to content

Commit 1dec270

Browse files
authored
Add command line option to select which completor to use (#754)
* Add command line option to select which completor to use * Add test for completor argv
1 parent a9d0145 commit 1dec270

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ IRB's default completion `IRB::RegexpCompletor` uses Regexp. IRB has another exp
241241

242242
### How to Enable IRB::TypeCompletion
243243

244-
To enable IRB::TypeCompletion, write the code below to IRB's rc-file.
244+
To enable IRB::TypeCompletion, run IRB with `--type-completor` option
245+
```
246+
$ irb --type-completor
247+
```
248+
Or write the code below to IRB's rc-file.
245249
```ruby
246250
IRB.conf[:COMPLETOR] = :type # default is :regexp
247251
```

lib/irb/init.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ def IRB.parse_opts(argv: ::ARGV)
330330
@CONF[:USE_AUTOCOMPLETE] = true
331331
when "--noautocomplete"
332332
@CONF[:USE_AUTOCOMPLETE] = false
333+
when "--regexp-completor"
334+
@CONF[:COMPLETOR] = :regexp
335+
when "--type-completor"
336+
@CONF[:COMPLETOR] = :type
333337
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
334338
opt = $1 || argv.shift
335339
prompt_mode = opt.upcase.tr("-", "_").intern

lib/irb/lc/help-message

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Usage: irb.rb [options] [programfile] [arguments]
3030
--nocolorize Don't use color-highlighting.
3131
--autocomplete Use auto-completion (default).
3232
--noautocomplete Don't use auto-completion.
33+
--regexp-completor
34+
Use regexp based completion (default).
35+
--type-completor Use type based completion.
3336
--prompt prompt-mode, --prompt-mode prompt-mode
3437
Set prompt mode. Pre-defined prompt modes are:
3538
'default', 'classic', 'simple', 'inf-ruby', 'xmp', 'null'.

lib/irb/lc/ja/help-message

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Usage: irb.rb [options] [programfile] [arguments]
2121
--nocolorize 色付けを利用しない.
2222
--autocomplete オートコンプリートを利用する.
2323
--noautocomplete オートコンプリートを利用しない.
24+
--regexp-completor
25+
補完に正規表現を利用する.
26+
--type-completor 補完に型情報を利用する.
2427
--prompt prompt-mode/--prompt-mode prompt-mode
2528
プロンプトモードを切替えます. 現在定義されているプ
2629
ロンプトモードは, default, simple, xmp, inf-rubyが

man/irb.1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ Use autocompletion.
140140
Don't use autocompletion.
141141
.Pp
142142
.Pp
143+
.It Fl -regexp-completor
144+
Use regexp based completion.
145+
.Pp
146+
.It Fl -type-completor
147+
Use type based completion.
148+
.Pp
149+
.Pp
143150
.It Fl -verbose
144151
Show details.
145152
.Pp

test/irb/test_init.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ def test_use_autocomplete_environment_variable
120120
IRB.conf[:USE_AUTOCOMPLETE] = orig_use_autocomplete_conf
121121
end
122122

123+
def test_completor_setup_with_argv
124+
orig_completor_conf = IRB.conf[:COMPLETOR]
125+
126+
# Default is :regexp
127+
IRB.setup(__FILE__, argv: [])
128+
assert_equal :regexp, IRB.conf[:COMPLETOR]
129+
130+
IRB.setup(__FILE__, argv: ['--type-completor'])
131+
assert_equal :type, IRB.conf[:COMPLETOR]
132+
133+
IRB.setup(__FILE__, argv: ['--regexp-completor'])
134+
assert_equal :regexp, IRB.conf[:COMPLETOR]
135+
ensure
136+
IRB.conf[:COMPLETOR] = orig_completor_conf
137+
end
138+
123139
def test_noscript
124140
argv = %w[--noscript -- -f]
125141
IRB.setup(eval("__FILE__"), argv: argv)

0 commit comments

Comments
 (0)