Commit graph

899 commits

Author SHA1 Message Date
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
st0012
81b604fb00 [ruby/irb] Use require_relative to require lib files
1. `require` can mislead Ruby to load system irb's files and cause
   constant redefined warnings as other code loads the same module/class
   from lib folder.
2. Most files already use `require_relative`.

848d339f2e
2022-01-17 14:23:40 +09:00
Samuel Williams
e4cd319f3d [ruby/irb] Prefer IO#wait_readable over IO#select. (https://github.com/ruby/irb/pull/323)
1c03bd3373
2021-12-29 09:37:05 +09:00
aycabta
0f1fbc6421 [ruby/irb] Version 1.4.1
b1d9c34441
2021-12-25 12:57:28 +09:00
aycabta
ddf0cdee4f [ruby/irb] Support showing doc by dialog in iTerm2
a4b95d6634
2021-12-25 12:56:40 +09:00
aycabta
90239c4163 [ruby/irb] Version 1.4.0
b80ec5821e
2021-12-25 00:41:04 +09:00
aycabta
214b6128ae [ruby/irb] Update dependency, reline >= 0.3.0
f36ad549c4
2021-12-25 00:41:03 +09:00
manga_osyo
f279d41847 Fix warning in Lexer::Elem#[]
Changed to use `#pos` `#event` `#tok` `#state` since using Lexer::Elem#[0~4] now gives a warning.
see: 8944009be7

9adbb9af32
2021-12-24 20:44:02 +09:00
YO4
de0523fedd [ruby/irb] irb_info codepage mismatch
`chcp` returns different encoding

f80971994a
2021-12-24 10:32:14 +09:00
aycabta
b96ef7684c [ruby/irb] Add East Asian Ambiguous Width to irb_info command
4cade4b7e5
2021-12-20 16:19:36 +09:00
Kaíque Kandy Koga
6b64e78823 [ruby/irb] Examine indentation of in keyword when trying to type include
Use in_keyword_case_scope?

Return fast

8acc7f8dc7
2021-12-03 00:56:43 +09:00
ima1zumi
d486286f1d [ruby/irb] Add Alt+d keycode when convert-meta isn't used
I pushed reline#389 for when convert-meta is not turned on in .inputrc.
Alt+D in irb also needs to be set to the keycode for not using convert-meta.

328eddf851
2021-12-03 00:51:41 +09:00
manga_osyo
dcbe29d2ae [ruby/irb] Fix bug infinite loop when pasting multilines fo code in Ruby 2.6
Fix bug infinite loop when pasting multilines fo code in Ruby 2.6.
This is not reproduced in Ruby 2.7.
Changes added in https://github.com/ruby/irb/pull/242/files#diff-612b926e42ed78aed1a889ac1944f7d22229b3a489cc08f837a7f75eca3d3399R155 are also reflected in Ruby 2.6.

0a77f75bf0
2021-12-03 00:42:28 +09:00
schneems
2b22c93533 Compatibility with IRB
Instead of accessing the struct as an array, access it via methods. There are other places inside of this file already using this API (for example e0a5c3d2b7/lib/irb/ruby-lex.rb (L829-L830)).

This commit moves all struct array-ish calls to use their method calls instead. It is also ~1.23 faster accessing values via a method instead of as an array according to this microbenchmark:

```ruby
Elem = Struct.new(:pos, :event, :tok, :state, :message) do
  def initialize(pos, event, tok, state, message = nil)
    super(pos, event, tok, State.new(state), message)
  end

  # ...

  def to_a
    a = super
    a.pop unless a.empty?
    a
  end
end

class ElemClass
  attr_accessor :pos, :event, :tok, :state, :message

  def initialize(pos, event, tok, state, message = nil)
    @pos = pos
    @event = event
    @tok = tok
    @state = State.new(state)
    @message = message
  end

  def to_a
    if @message
      [@pos, @event, @tok, @state, @message]
    else
      [@pos, @event, @tok, @state]
    end
  end
end

# stub state class creation for now
class State; def initialize(val); end; end
```

```ruby
Benchmark.ips do |x|
  x.report("struct") { struct[1] }
  x.report("class ") { from_class.event }
  x.compare!
end; nil
```

```
Warming up --------------------------------------
              struct     1.624M i/100ms
              class      1.958M i/100ms
Calculating -------------------------------------
              struct     17.139M (± 2.6%) i/s -     86.077M in   5.025801s
              class      21.104M (± 3.4%) i/s -    105.709M in   5.015193s

Comparison:
              class : 21103826.3 i/s
              struct: 17139201.5 i/s - 1.23x  (± 0.00) slower
```
2021-12-02 15:55:42 +09:00
Kaíque Kandy Koga
5c646ca0a0 [ruby/irb] Ignore parenthesis during completion
Rename method

619aecb412
2021-10-13 06:33:48 +09:00
aycabta
7732052718 [ruby/irb] Add help about extra doc dir option
5018f2cb99
2021-10-11 21:12:58 +09:00