Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command line option to select which completor to use #754

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ IRB's default completion `IRB::RegexpCompletor` uses Regexp. IRB has another exp

### How to Enable IRB::TypeCompletion

To enable IRB::TypeCompletion, write the code below to IRB's rc-file.
To enable IRB::TypeCompletion, run IRB with `--type-completor` option
```
$ irb --type-completor
```
Or write the code below to IRB's rc-file.
```ruby
IRB.conf[:COMPLETOR] = :type # default is :regexp
```
Expand Down
4 changes: 4 additions & 0 deletions lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ def IRB.parse_opts(argv: ::ARGV)
@CONF[:USE_AUTOCOMPLETE] = true
when "--noautocomplete"
@CONF[:USE_AUTOCOMPLETE] = false
when "--regexp-completor"
@CONF[:COMPLETOR] = :regexp
when "--type-completor"
@CONF[:COMPLETOR] = :type
st0012 marked this conversation as resolved.
Show resolved Hide resolved
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
opt = $1 || argv.shift
prompt_mode = opt.upcase.tr("-", "_").intern
Expand Down
3 changes: 3 additions & 0 deletions lib/irb/lc/help-message
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Usage: irb.rb [options] [programfile] [arguments]
--nocolorize Don't use color-highlighting.
--autocomplete Use auto-completion (default).
--noautocomplete Don't use auto-completion.
--regexp-completor
Use regexp based completion (default).
--type-completor Use type based completion.
--prompt prompt-mode, --prompt-mode prompt-mode
Set prompt mode. Pre-defined prompt modes are:
'default', 'classic', 'simple', 'inf-ruby', 'xmp', 'null'.
Expand Down
3 changes: 3 additions & 0 deletions lib/irb/lc/ja/help-message
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Usage: irb.rb [options] [programfile] [arguments]
--nocolorize 色付けを利用しない.
--autocomplete オートコンプリートを利用する.
--noautocomplete オートコンプリートを利用しない.
--regexp-completor
補完に正規表現を利用する.
--type-completor 補完に型情報を利用する.
--prompt prompt-mode/--prompt-mode prompt-mode
プロンプトモードを切替えます. 現在定義されているプ
ロンプトモードは, default, simple, xmp, inf-rubyが
Expand Down
7 changes: 7 additions & 0 deletions man/irb.1
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ Use autocompletion.
Don't use autocompletion.
.Pp
.Pp
.It Fl -regexp-completor
Use regexp based completion.
.Pp
.It Fl -type-completor
Use type based completion.
.Pp
.Pp
.It Fl -verbose
Show details.
.Pp
Expand Down
16 changes: 16 additions & 0 deletions test/irb/test_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ def test_use_autocomplete_environment_variable
IRB.conf[:USE_AUTOCOMPLETE] = orig_use_autocomplete_conf
end

def test_completor_setup_with_argv
orig_completor_conf = IRB.conf[:COMPLETOR]

# Default is :regexp
IRB.setup(__FILE__, argv: [])
assert_equal :regexp, IRB.conf[:COMPLETOR]

IRB.setup(__FILE__, argv: ['--type-completor'])
assert_equal :type, IRB.conf[:COMPLETOR]

IRB.setup(__FILE__, argv: ['--regexp-completor'])
assert_equal :regexp, IRB.conf[:COMPLETOR]
ensure
IRB.conf[:COMPLETOR] = orig_completor_conf
end

def test_noscript
argv = %w[--noscript -- -f]
IRB.setup(eval("__FILE__"), argv: argv)
Expand Down