Commit graph

764 commits

Author SHA1 Message Date
st0012
923c1aaed7
Drop Ruby 2.5 support
Because it has reached EOL for more than 1.5 years and it won't be
supported by the next reline version either.
2022-11-17 13:06:32 +09:00
Patrick Plenefisch
e61b3e6f43 [ruby/irb] Fix https://github.com/ruby/irb/pull/295: Ignore Java
package reference objects in
JRuby

84d030182d
2022-11-17 03:39:04 +00:00
st0012
aecb7f6efc [ruby/irb] Deprecate USE_RELINE and USE_REIDLINE
Based on this commit: 93f87ec653

It appears that the maintainer @aycabta wanted to deprecate any `USE_*LINE` configs in favor of
`USE_MULTILINE`. So we should deprecate `USE_RELINE` as well.

478f19f3ae
2022-11-15 10:08:30 +00:00
st0012
34320d883f [ruby/irb] Deprecate reidline flags
9957e83f7d
2022-11-15 10:08:29 +00:00
st0012
4f348e482c [ruby/irb] Rename leftover Reidline references
0ed8b103ed
2022-11-15 10:08:28 +00:00
Takashi Kokubun
8fa83fa0b2 [ruby/irb] Transform ls's --grep/-G option to keyword args
(https://github.com/ruby/irb/pull/437)

* Transform ls's --grep/-G option to keyword args

* Make --grep less flexible

* Support -g instead of --grep

* Suppress warnings from symbol aliases
2022-11-10 22:55:15 +00:00
Takashi Kokubun
0de3bc92b4 [ruby/irb] Make $ and @ default aliases
(https://github.com/ruby/irb/pull/438)

0613589476
2022-11-10 17:31:15 +00:00
Takashi Kokubun
9001e53e68 [ruby/irb] Support non-string input in show_source
(https://github.com/ruby/irb/pull/430)

* Support non-string input in show_source

* Test show_source as a method
2022-11-07 17:29:28 +00:00
Stan Lo
ca0b592673 [ruby/irb] Don't lazily retrieve gem specs for completion
There are a few downsides of the current approach:

1. Because gem specs are lazily retrieved, this computation happens in
   every irb completion test case, which is not necessary. (In tests we
   don't cache the result of `retrieve_files_to_require_from_load_path`)
2. Gem::Specification.latest_specs is sensible to the content of
   LOAD_PATH. And when combined with 1, tests fail "randomly" if they
   try to mutate LOAD_PATH, even though the test subject it's something
   else.

So by pre-computing and storing the gem paths in a constant, it guarantees
that the computation only happens once and it doesn't get affected by test
cases.

One argument could be made against the change is that, it'll store
unnecessary data for users that disable autocompletion. But the
counter-arguments are:

1. Since autocompletion is enabled by default, this should not be the
   case for most users.
2. For users with autocompletion enabled, IRB already caches the
   result of `retrieve_files_to_require_from_load_path` in memory, which
   should have a similar size of GEM_SPECS. And we currently haven't
   received any report about problems caused by such memory consumption.

c671d39020
2022-11-07 14:44:25 +00:00
Takashi Kokubun
a13836e70d [ruby/irb] Allow non-identifier aliases like Pry's @ and $
(https://github.com/ruby/irb/pull/426)

* Allow non-identifier aliases

* Move the configuration to IRB.conf

* Avoid abusing method lookup for symbol aliases

* Add more alias tests

* A small optimization

* Assume non-nil Context

* Load IRB.conf earlier

e23db5132e
2022-11-03 22:09:55 +00:00
Stan Lo
c5d6a483f5 [ruby/irb] Refactor RubyLex and its tests
(https://github.com/ruby/irb/pull/427)

* Make sure `RubyLex#set_input`'s context is always present in tests

In real-world scenarios, the context should always be non-nil:
https://github.com/ruby/irb/blob/master/lib/irb.rb#L489

So we should make sure our test setup reflects that.

* Make context a required keyword

Since in practice, `set_input`'s context should always be non-nil, its
parameters should reflect that.

And since `RubyLex#check_state` is only called by `#lex` and
`#set_input`, both of which now always require context, we can assume
its context should be non-nil too.

1aeeb86203
2022-11-03 16:32:22 +00:00
Nobuyoshi Nakada
4021c6565f [ruby/irb] Do not make non-existent XDG directory on start
(https://github.com/ruby/irb/pull/357)


298b134792
2022-10-28 09:36:28 +00:00
Nobuyoshi Nakada
56c97a6621 [ruby/irb] Update regarding NO_COLOR value
https://no-color.org has been updated (jcs/no_color#83):

> Command-line software which adds ANSI color to its output by default
should check for a `NO_COLOR` environment variable that, when present
and **not an empty string** (regardless of its value), prevents the
addition of ANSI color.

46e0f7e370

Co-authored-by: Stan Lo <stan001212@gmail.com>
2022-10-28 09:30:24 +00:00
st0012
b7622d792d [ruby/irb] Move require out of repeated execution path
SHOW_DOC_DIALOG will be called repeatedly whenever the corresponding key
is pressed, but we only need to require rdoc once. So ideally the
require can be put outside of the proc.

And because when rdoc is not available the entire proc will be
nonfunctional, we can stop registering the SHOW_DOC_DIALOG if we failed
to require rdoc.

b1278b7320
2022-10-24 13:36:57 +00:00
Takashi Kokubun
931bcd1b63 [ruby/irb] Assert lvars_code doesn't include \n
Removing /\A.+\n/ could have an unexpected impact, depending on how
RubyLex.generate_local_variables_assign_code is implemented. It feels
like a too much assumption and the intention isn't immediately clear,
so I added these changes.

ccc07a35ce
2022-10-18 06:03:23 +00:00
tomoya ishida
a09f764ce5 [ruby/irb] Always use local variables in current context to parse code (https://github.com/ruby/irb/pull/397)
* Use local_variables for colorize, code_block_open check, nesting_level and assignment_expression check

* Check if expression is an assignment BEFORE evaluating it. evaluate might define new localvars and change result of assignment_expression?

* Add local_variables dependent code test

* pend local variable dependent test on truffleruby

code_block_open is not working on truffleruby

* Always pass context to RubyLex#lex

* Rename local_variable_assign_code generator method name

* Add assignment expression truncate test

* Add Context#local_variables and make generate_local_variables_assign_code more simple

* Update lib/irb/input-method.rb

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Add a comment why assignment expression check should be done before evaluate

c8b3877281

Co-authored-by: Stan Lo <stan001212@gmail.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-10-18 05:44:07 +00:00
tomoya ishida
344e6c915f [ruby/irb] Fix code terminated check with heredoc and backtick (https://github.com/ruby/irb/pull/390)
* Fix backtick method def method call handled as backtick open

* Fix handling heredoc in check_string_literal

* Sort result of lexer.parse by pos in ruby<2.7. It's not sorted when the given code includes heredoc.

* Update lib/irb/ruby-lex.rb

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Update lib/irb/ruby-lex.rb

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Add check_string_literal test for heredoc code that does not end with newline

44bc712460

Co-authored-by: Stan Lo <stan001212@gmail.com>
2022-10-18 05:30:33 +00:00
st0012
5b3079a8a5 [ruby/irb] Sort constant completion's candidates
ee9b33c817
2022-10-08 03:17:42 +09:00
st0012
7cafe09aec [ruby/irb] Lazily evaluate candidates locals
19a2fcbd87
2022-10-08 03:17:42 +09:00
Imir Kiyamov
83a6213f31 [ruby/irb] Fixed sort of variables in completion
5842888255
2022-10-05 19:22:13 +09:00
Kaíque Kandy Koga
d880322243 [ruby/irb] Update remark of self.install_extend_commands.
Create line

64d6a461d5
2022-10-05 19:15:28 +09:00
Hiroshi SHIBATA
2f6a263787 [ruby/irb] Use USE_REIDLINE for backword compatibility
e58a3c1b39
2022-10-05 18:59:31 +09:00
Gannon McGibbon
19e4a4c624 [ruby/irb] Rename IDB::ReidlineInputMethod to IRB::RelineInputMethod
Deprecates IDB::ReidlineInputMethod and USE_REIDLINE in favor of
IRB::RelineInputMethod and USE_RELINE. The Input method uses Reline to
read input from the console, so it can be named directly after the
Reline library like other inputs methods are (Readline, Stdio, etc.).

5bcade7130
2022-10-05 17:14:19 +09:00
st0012
203b831065 [ruby/irb] Bump version to 1.4.2
f9960dbd37
2022-10-05 15:25:02 +09:00
Hiroshi SHIBATA
f081bba875 [ruby/irb] Added aycabta to authors
a6bfa7b2e6
2022-10-05 15:15:33 +09:00
st0012
10e830c25b [ruby/irb] Remove unused error
f09a1874b6
2022-10-03 07:00:54 +09:00
st0012
b97e909ef4 [ruby/irb] Remove unnecessary Thread presence check
They were introduced around 20 years ago, when Thread is not yet
stabilized. So we don't need them anymore.

4c75e03b2b
2022-10-03 07:00:53 +09:00
osyo-manga
7b88ffb34f [ruby/irb] Change to explicit method call in completion (https://github.com/ruby/irb/pull/369)
Ensure that methods are called even when local variables are defined.
see: https://github.com/ruby/irb/issues/368

c34d54b8bb
2022-10-03 06:55:53 +09:00
st0012
5cab9d0ee2 [ruby/irb] Remove patches for Ruby 2.4
They were added in b34f26a0dd

0e760d2674
2022-10-03 04:59:51 +09:00
st0012
42fcbcc215 [ruby/irb] Remove unnecessary condition
daffb8bfe5
2022-10-03 04:59:50 +09:00
st0012
55e2116f2c [ruby/irb] Refactor ripper_lex_without_warning
0db0a8ddc5
2022-10-03 04:59:49 +09:00
tompng
641310ce37 [ruby/irb] Fix ripper_lex_without_warning duplicated heredoc token
45b539af39
2022-10-01 04:17:15 +09:00
tompng
369f1668cd [ruby/irb] Rewrite on_scan proc to be more readable.
da54e7f081
2022-09-22 00:37:40 +09:00
tompng
9f68687879 [ruby/irb] Scan every single characters in IRB::Color.scan
d14e56a65d
2022-09-22 00:37:38 +09:00
st0012
6325fc8854 [ruby/irb] Handle non-String $LOAD_PATH values more carefully
In addition to String values, $LOAD_PATH can also take objects that
respond_to the `to_path` method, like Pathname objects. So `irb` should
be able to handle those objects too.

And if $LOAD_PATH contains objects that can't be converted into String,
`irb` should simply ignore it.

b2f562176b
2022-09-21 22:24:27 +09:00
Jeremy Evans
b07db96744 [ruby/irb] Support --noscript option to not use first non-option argument as script
Also add --script option to turn the option back on.

Previously there wasn't a way to get an interactive IRB session
and access arguments provided on the command line.

Additionally, handle `-` as script as stdin. In Unix-like tools, `-`
means to take standard input instead of a file.  This doesn't
result in exactly the same output for:

```
echo 'p ARGV' > args.rb; irb args.rb a b c
```

and

```
echo 'p ARGV' | irb - a b c
```

Due to how irb handles whether stdin is a tty.

However, this change allows use of `-` as a argument, instead of
giving an unrecognized switch error. This required some small
changes to context.rb (to handle `-` as standard input) and
input-method.rb (to have FileInputMethod accept IO arguments in
addition to strings).

Implements [Feature #15371]

4192683ba2
2022-09-17 02:25:26 +09:00
Nobuyoshi Nakada
f863bc505c [ruby/irb] Fix the error when LC_MESSAGES config value is nil
6bbde84369
2022-09-14 11:14:08 +09:00
Jeremy Evans
9299db49f5 [ruby/irb] Fix history file saving with concurrent irb sessions when history file doesn't exist
If history file didn't exist when irb was started, @loaded_history_mtime
would be nil.  However, if the history file didn't exist before, but it
exists when saving history, that means the history file was modified,
and we should handle it the same way as we handle the other case where
the history file was modified.

Fixes #388

8d277aafcb
2022-09-14 10:15:45 +09:00
Jun Aruga
3504be1bc1 [ruby/irb] Require RDoc in input-method.rb again in a limited scope.
RDoc is implemented as soft dependency in IRB. See how the rdoc is required in
the files. I reverted the commit below.

```
$ grep -ril rdoc lib/
lib/irb/cmd/help.rb
lib/irb/completion.rb
lib/irb/easter-egg.rb
lib/irb/input-method.rb
```

---

Revert "Remove `require` in signal handler to avoid ThreadError"

This reverts commit 5f749c613c.

b24852058f
2022-08-26 09:57:02 +09:00
Vít Ondruch
46c3a93982 [ruby/irb] Drop hard dependency on RDoc.
This has been introduced in 026700499d,
but it seems that this is just be mistake, otherwise the later handling
of `LoadError` would not be needed.

54c8df06ff
2022-08-23 18:01:35 +09:00
tompng
b54f26b704 [ruby/irb] shortcut colorize_code to speedup pretty_print
8a074a6904
2022-08-04 08:37:03 +09:00
Burdette Lamar
66dfcbed37 [ruby/irb] [DOC] Include updated help message (https://github.com/ruby/irb/pull/377)
* Include updated help message

ff129f3794
2022-07-12 00:05:15 +09:00
Burdette Lamar
55c5bf27f5 [ruby/irb] Additions/revisions to help-message (https://github.com/ruby/irb/pull/370)
Changed:

    Added text to options that said just 'same as ruby -whatever'.
    Added defaults.
    Removed an errant tab.

dfe454cc33
2022-07-08 03:15:47 +09:00
st0012
7d211c93af [ruby/irb] Color.colorable? needs to consider the condition when irb is not loaded
ruby/debug uses `irb/color` selectively:
0ac22406bb/lib/debug/color.rb (L4)

And in that case, `IRB.conf` won't be defined. So Color.colorable? needs
to consider that.

This also fixes the Ruby trunk CI.

b2cd07e795
2022-06-28 22:57:17 +09:00
Stan Lo
44c1316293 [ruby/irb] Centralize coloring control (https://github.com/ruby/irb/pull/374)
* Use colorable: argument as the only coloring control

* Centalize color controling logic at Color.colorable?

There are 2 requirements for coloring output:

1. It's supported on the platform
2. The user wants it: `IRB.conf[:USE_COLORIZE] == true`

Right now we check 1 and 2 separately whenever we colorize things.
But it's error-prone because while 1 is the default of `colorable`
parameter, 2 always need to manually checked. When 2 is overlooked, it
causes issues like https://github.com/ruby/irb/pull/362

And there's 0 case where we may want to colorize even when the user
disables it. So I think we should merge 2 into `Color.colorable?` so it
can be automatically picked up.

* Add tests for all inspect modes

* Simplify inspectors' coloring logic

* Replace use_colorize? with Color.colorable?

* Remove Context#use_colorize cause it's redundant

1c53023ac4
2022-06-28 22:30:42 +09:00
Peter Jones
e0bfdb23af [ruby/irb] Ensure stdout is a TTY before calling winsize
When outputting a (possibly truncated) value, IRB will query the
window size.  However, if IRB was piped to another process, stdout
will no longer be a TTY and will not support the `winsize` method.

This fix ensure that stdout is a TTY.

125de5eeea
2022-06-26 14:40:48 +09:00
Stan Lo
2d4a41df6b [ruby/irb] Commands should respect USE_COLORIZE config (https://github.com/ruby/irb/pull/362)
534688dfc4
2022-06-20 22:27:30 +09:00
Nobuyoshi Nakada
8760b270ed [ruby/irb] Move :stopdoc: directive
If this is at the top level, it stops the documentation of the
entire module, but not only the part in this file.

86c41b06ad
2022-03-14 14:40:28 +09:00
manga_osyo
b6b2e489f1 [ruby/irb] Changed to call Kernel.print
If you call `binding.irb` on a class defined `#print`, it will crash, so call `Kernel.print`.

Fix [Bug #18389] `binding.irb` can fail in some classes that implement `context` and `print` methods.

d54b271984
2022-01-27 01:28:52 +09:00
st0012
e53962b9e1 [ruby/irb] Use require_relative to load extensions/commands
d5060f7668
2022-01-17 21:09:36 +09:00