Граф коммитов

983 Коммитов

Автор SHA1 Сообщение Дата
Stan Lo e1d7066a5f [ruby/irb] Deprecate RubyLex and warn about referencing to it
(https://github.com/ruby/irb/pull/692)

`RubyLex` has always been a private component of IRB, so we should
explicitly discourage usages of it.
Also, it should be placed under the `IRB` module like other components.

https://github.com/ruby/irb/commit/069b5625f7
2023-08-24 15:35:40 +00:00
Stan Lo ca6db02c2a [ruby/irb] Avoid overriding user's `irb_name` setting in debugger
integration
(https://github.com/ruby/irb/pull/688)

* Avoid overriding user's irb_name setting in debugger integration

Instead of always setting `irb_name` to `irb:rdbg`, it should respect
the user's setting and only append `:rdbg` to it.

* Introduce write_rc test helper

https://github.com/ruby/irb/commit/2ce7593351
2023-08-21 18:23:32 +00:00
Stan Lo 86ac17efde [ruby/irb] Move input processing out of RubyLex
(https://github.com/ruby/irb/pull/683)

* Add a test case for Ctrl-C handling

* Test symbol aliases with integration tests

There are a few places that also need to check symbol aliases before
`Irb#eval_input`. But since the current command test skip them, we
don't have test coverage on them.

* Move each_top_level_statement and readmultiline to Irb

This will save RubyLex from knowning information about commands and aliases.

https://github.com/ruby/irb/commit/69cb5b5615
2023-08-21 15:42:15 +00:00
Summer ☀️ 725ca2f9d8 [ruby/irb] Support `VISUAL` env var, and prefer it over `EDITOR`
(https://github.com/ruby/irb/pull/686)

* Support `VISUAL` env var, and prefer it over `EDITOR`

* Update test/irb/test_cmd.rb

---------

https://github.com/ruby/irb/commit/399b872c31

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-08-20 17:22:01 +00:00
Stan Lo 5a40f7db54 [ruby/irb] Encapsulate input details in Statement objects
(https://github.com/ruby/irb/pull/682)

* Introduce Statement class

* Split Statement class for better clarity

https://github.com/ruby/irb/commit/65e8e68690
2023-08-16 10:13:46 +00:00
Stan Lo 7f8f62c93b [ruby/irb] Support seamless integration with ruby/debug
(https://github.com/ruby/irb/pull/575)

* Support native integration with ruby/debug

* Prevent using multi-irb and activating debugger at the same time

Multi-irb makes a few assumptions:

- IRB will manage all threads that host sub-irb sessions
- All IRB sessions will be run on the threads created by IRB itself

However, when using the debugger these assumptions are broken:

- `debug` will freeze ALL threads when it suspends the session (e.g. when
  hitting a breakpoint, or performing step-debugging).
- Since the irb-debug integration runs IRB as the debugger's interface,
  it will be run on the debugger's thread, which is not managed by IRB.

So we should prevent the 2 features from being used at the same time.
To do that, we check if the other feature is already activated when
executing the commands that would activate the other feature.

https://github.com/ruby/irb/commit/d8fb3246be
2023-08-13 18:30:34 +00:00
Stan Lo 9099d62ac7 [ruby/irb] Move IO configuration to IRB::Irb
(https://github.com/ruby/irb/pull/681)

It shouldn't be `RubyLex`'s responsibility to handle IO. So this moves
the configuration to `IRB::Irb`.

https://github.com/ruby/irb/commit/daff750076
2023-08-13 15:23:04 +00:00
Nobuyoshi Nakada 3af5badae8 [ruby/irb] Remove useless `begin`/`end` [ci skip]
(https://github.com/ruby/irb/pull/680)

The `rescue` was removed at https://github.com/ruby/irb/commit/420e7d227011.

https://github.com/ruby/irb/commit/8fa688e9c0
2023-08-13 15:02:29 +00:00
tomoya ishida e1683b4958 [ruby/irb] Drop showing indent level number in DEFAULT prompt and
INF_RUBY prompt
(https://github.com/ruby/irb/pull/679)

* Drop showing indent level number in DEFAULT prompt and INF_RUBY prompt

* Update prompt part of test_rendering's expected result

https://github.com/ruby/irb/commit/3847532e54
2023-08-12 10:19:24 +00:00
Stan Lo 680835085d [ruby/irb] Reline/ReadlineInputMethod should inherit
StdioInputMethod
(https://github.com/ruby/irb/pull/671)

They are both built on top of stdio and are basically extended version
of StdioInputMethod. They also share several attributes and methods with
StdioInputMethod.

https://github.com/ruby/irb/commit/c5f5abdbde
2023-08-12 10:17:52 +00:00
tomoya ishida d42891079f [ruby/irb] Remove needless removal of trailing whitespace in
check_code_state
(https://github.com/ruby/irb/pull/678)

https://github.com/ruby/irb/commit/4a6af7d1ed
2023-08-11 18:51:25 +00:00
Stan Lo 0781e55206 [ruby/irb] Move assignment check to RubyLex
(https://github.com/ruby/irb/pull/670)

Since assignment check relies on tokenization with `Ripper`, it feels like
the responsibility of `RubyLex`. `Irb#eval_input` should simply get the result
when calling `each_top_level_statement` on `RubyLex`.

https://github.com/ruby/irb/commit/89d1adb3fd
2023-08-11 18:44:52 +00:00
Stan Lo d3311e5cc3 [ruby/irb] Add black and white color to IRB::Color
(https://github.com/ruby/irb/pull/676)

https://github.com/ruby/irb/commit/a2763acade
2023-08-11 16:03:11 +00:00
Stan Lo ab0f90f1f5 [ruby/irb] Fix nested IRB sessions' history saving
(https://github.com/ruby/irb/pull/652)

1. Dynamically including `HistorySavingAbility` makes things unnecessarily
   complicated and should be avoided.
2. Because both `Reline` and `Readline` use a single `HISTORY` constant
   to store history data. When nesting IRB sessions, only the first IRB
   session should handle history loading and saving so we can avoid
   duplicating history.
3. History saving callback should NOT be stored in `IRB.conf` as it's
   recreated every time `IRB.setup` is called, which would happen when
   nesting IRB sessions.

https://github.com/ruby/irb/commit/0fef0ae160
2023-08-09 14:57:52 +00:00
Stan Lo 0387b86c3a [ruby/irb] Remove unused `InputMethod#initialize`
(https://github.com/ruby/irb/pull/635)

* Remove unused InputMethod#initialize

The constructor takes a `file_name` argument, but it is never used. The
only input method that needs a file is `FileInputMethod`, which has its
own constructor to take a file object directly.

So the constructor in `InputMethod` is not needed and its child classes
don't need to call `super` in their constructors.

* Remove unused FileInputMethod#file_name

https://github.com/ruby/irb/commit/153b1e9d1c
2023-08-07 15:30:13 +00:00
Stan Lo 32e828bb4a [ruby/irb] Deprecate multi-irb commands
(https://github.com/ruby/irb/pull/654)

* Deprecate multi-irb commands

- Print deprecated message when any of the commands are used
- Put related commands under `Multi-irb` category with a deprecated
  label

* Update readme

https://github.com/ruby/irb/commit/861731ac12
2023-08-02 18:35:08 +00:00
Stan Lo 201fd57518 [ruby/irb] Drop src_encoding.rb
(https://github.com/ruby/irb/pull/634)

Its method `IRB.default_src_encoding` was only used in `magic-file.rb`,
which has been removed.

https://github.com/ruby/irb/commit/ed98983b1f
2023-08-02 18:17:27 +09:00
Stan Lo f11ac06337 [ruby/irb] Add workspace category
(https://github.com/ruby/irb/pull/661)

* Create a new Workspace command category

* Update readme

https://github.com/ruby/irb/commit/310650c213
2023-08-01 12:51:30 +00:00
Stan Lo 5d78ec8a94 [ruby/irb] Decouple `edit` and `show_source` commands
(https://github.com/ruby/irb/pull/658)

* Decouple `edit` command from `show_source`

2 commands should not depend on each other. If `edit` command also needs
to find a source, the source finding logic should be extracted into a
separate class.

* Return nil if is not an actual file path

* Refactor SourceFinder

https://github.com/ruby/irb/commit/9790517a0c
2023-07-31 19:57:36 +00:00
Stan Lo 283b2fdab4 [ruby/irb] Page `ls`'s output (https://github.com/ruby/irb/pull/657)
* Page ls command's output

* Use Pager.page_content in show_cmds too

https://github.com/ruby/irb/commit/82d1687302
2023-07-26 08:32:02 +00:00
Stan Lo d8cee55073 [ruby/irb] Display `show_cmds`'s output in a pager when in TTY
environment
(https://github.com/ruby/irb/pull/647)

This can:

- Make it easier to scroll up and down the commands list
- Avoid pushing up users' previous output
- Allow users to do basic search with `/<word>`

https://github.com/ruby/irb/commit/f94e8a66dd
2023-07-25 18:33:23 +00:00
Stan Lo 0db58dd0db [ruby/irb] Declare rdoc as dependency
(https://github.com/ruby/irb/pull/648)

IRB already has several features that rely on rdoc, such as:

- Autocompletion's document dialog
- Autocompletion's `PerfectMatchedProc`
- The `show_doc` command
- Easter egg

And we could use its pager more in the future too. So it makes sense to
declare rdoc as a dependency instead of relying on the one bundled with
Ruby.

https://github.com/ruby/irb/commit/4dffbb1dd3
2023-07-18 13:53:31 +00:00
tomoya ishida be98bfc4ee [ruby/irb] Indent multiline percent literals
(https://github.com/ruby/irb/pull/643)

https://github.com/ruby/irb/commit/18bb4022a9
2023-07-15 18:12:05 +00:00
ima1zumi 7ffb995f5e [ruby/irb] Bump 1.7.4 (https://github.com/ruby/irb/pull/645)
https://github.com/ruby/irb/commit/b0f650a766
2023-07-15 15:59:18 +00:00
Stan Lo 174bc22570 [ruby/irb] Fix history-saving feature
(https://github.com/ruby/irb/pull/642)

* Define RelineInputMethod::HISTORY

The HistorySavingAbility module doesn't do anything if the input method
class doesn't define HISTORY.

- 3ac96be660/lib/irb/history.rb (L10)
- 3ac96be660/lib/irb/history.rb (L34)

This patch defines RelineInputMethod::HISTORY to avoid this.

* Improve history-saving's ability check

Instead of checking the existence of `input_method_class::HISTORY`, we should
make every input method class declare if it supports history saving or not.

Since the default value is `false`, it shouldn't break any custom input method
that inherits from `IRB::InputMethod`.

https://github.com/ruby/irb/commit/aec7a5b3f5
2023-07-14 15:45:09 +00:00
Stan Lo 7f9c2a9bdd [ruby/irb] Bump version to 1.7.3
(https://github.com/ruby/irb/pull/639)

https://github.com/ruby/irb/commit/621c8c2b7d
2023-07-13 02:16:04 +00:00
Stan Lo 81beb29988 [ruby/irb] Correct preferred_dialog_height's caller
(https://github.com/ruby/irb/pull/638)

The caller should be the dialog itself, not Reline.

https://github.com/ruby/irb/commit/418c2b945e
2023-07-12 19:55:19 +00:00
ima1zumi d40935c680 [ruby/irb] Bump version to 1.7.2
(https://github.com/ruby/irb/pull/636)

https://github.com/ruby/irb/commit/85d6b4d146
2023-07-11 16:30:34 +00:00
ima1zumi 4be92463b6 [ruby/irb] Require Reline 0.3.6 or higher
(https://github.com/ruby/irb/pull/632)

* Require Reline 0.3.6 or higher

"Multi-line multibyte regular expression raises exception" (https://github.com/ruby/irb/issues/627) is fixed in Reline 0.3.6.

* Remove unnecessary conditional
2023-07-11 14:47:26 +00:00
Stan Lo 4e2f98be39 [ruby/irb] Avoid using Reline as a module
(https://github.com/ruby/irb/pull/633)

Using it as a module makes it harder to understand methods' source.
2023-07-09 06:25:08 +00:00
Andy Waite fd6da40fef [ruby/irb] Use `max_by` for `longest_cmd_name_length`
(https://github.com/ruby/irb/pull/628)

https://github.com/ruby/irb/commit/5e87f3bfdd

Co-authored-by: Andy Waite <andyw8@users.noreply.github.com>
2023-07-04 20:45:07 +00:00
Stan Lo f6af5a1128 [ruby/irb] Refactor eval history
(https://github.com/ruby/irb/pull/623)

* Rename `ext/history.rb` to `ext/eval_history.rb`

To confusion with `lib/irb/history.rb`

* Add eval_history tests

* Rename eval_history's History to EvalHistory to avoid confusion
2023-07-04 15:17:41 +00:00
Stan Lo af9eeb19d8 [ruby/irb] Stop treating history-saving logic as extension
(https://github.com/ruby/irb/pull/613)

Since `IRB.conf[:SAVE_HISTORY]` is assigned with 1000 by default, history-saving
is a feature enabled by default. So it should not be treated as an extension,
which adds unnecessary complexity to the code.
2023-07-03 13:48:23 +00:00
Stan Lo 4bad2a9562 [ruby/irb] Bump version to 1.7.1
(https://github.com/ruby/irb/pull/621)

https://github.com/ruby/irb/commit/b9a9dd97df
2023-07-02 04:49:07 +00:00
Stan Lo 136fcd5118 [ruby/irb] Reduce internal operations' exposure to benchmarking
(https://github.com/ruby/irb/pull/618)

* Test last value is assigned with measure enabled

* Remove unnecessary `result` variable

`Context#evaluate` always assigns the result of the evaluation to `_` so
we don't need to do it in `Irb#eval_input`.

* Move benchmarking logic into `Context#evaluate`

Current location of the benchmarking logic is too high up and includes
operations like command loading and argument transformation, which should
be excluded. So this commit moves it into `Context#evaluate` to reduce the
noise.

We don't move it further down to `Workspace#evaluate` because `Context`
is an argument of the measure block, which is not available in `Workspace`.
2023-06-30 17:42:00 +00:00
tomoya ishida 9398734010 [ruby/irb] Re-implement prev_spaces feature for pasted code
(https://github.com/ruby/irb/pull/607)

https://github.com/ruby/irb/commit/9d97a192a5
2023-06-30 14:23:24 +00:00
tomoya ishida 8aedfefb21 [ruby/irb] Remove keyword exception from Context#evaluate because
the value is always nil
(https://github.com/ruby/irb/pull/617)

https://github.com/ruby/irb/commit/62691384f8
2023-06-27 20:43:53 +00:00
Stan Lo caddd0274b [ruby/irb] Move input line mutation out of `Context#evaluate`
(https://github.com/ruby/irb/pull/615)

This makes sure `Context#evaluate` really just evaluates the input.
It will also make #575's implementation cleaner.
2023-06-27 19:51:18 +00:00
tomoya ishida 00216c8aa0 [ruby/irb] Fix process_continue(rename to should_continue?) and
check_code_block(rename to check_code_syntax)
(https://github.com/ruby/irb/pull/611)

https://github.com/ruby/irb/commit/b7f4bfaaa4
2023-06-25 05:12:16 +00:00
tomoya ishida 406799cae8 [ruby/irb] Omit nesting_level, use indent_level to build prompt
string
(https://github.com/ruby/irb/pull/610)

https://github.com/ruby/irb/commit/f01ff0811b
2023-06-24 22:20:43 +00:00
tomoya ishida e25403d0d9 [ruby/irb] Improve indentation: bugfix, heredoc, embdoc, strings
(https://github.com/ruby/irb/pull/515)

* Implement heredoc embdoc and string indentation with bugfix

* Fix test_ruby_lex's indentation value

* Add embdoc indent test

* Add workaround for lines==[nil] passed to auto_indent when exit IRB with CTRL+d
2023-06-20 15:13:43 +00:00
tomoya ishida b8cd79c82f [ruby/irb] Add missing token that ignored by ripper
(https://github.com/ruby/irb/pull/608)

https://github.com/ruby/irb/commit/1cd3b45402
2023-06-19 10:38:24 +00:00
tomoya ishida 364a6d56d7 [ruby/irb] Rewrite RubyLex to fix some bugs and make it possible to
add new features easily
(https://github.com/ruby/irb/pull/500)

* Add nesting level parser for multiple use (indent, prompt, termination check)

* Rewrite RubyLex using NestingParser

* Add nesting parser tests, fix some existing tests

* Add description comment, rename method to NestingParser

* Add comments and tweak code to RubyLex

* Update NestingParser test

* Extract list of ltype tokens to constants
2023-06-15 15:39:58 +00:00
tomoya ishida 5d91be7c1f [ruby/irb] Use symbol.inspect instead of ":"+symbol.id2name to avoid
completion candidates including newline characters
(https://github.com/ruby/irb/pull/539)

https://github.com/ruby/irb/commit/aaf0c46645
2023-06-13 10:46:38 +00:00
Stan Lo e1ccb2838b [ruby/irb] Use `Kernel.warn` to print command alias warning
(https://github.com/ruby/irb/pull/601)

This aligns with other warnings in irb and properly channel the message
to stderr.
2023-06-10 15:01:46 +00:00
Stan Lo a41e088604 [ruby/irb] Remove the unused fork command definition
(https://github.com/ruby/irb/pull/600)

https://github.com/ruby/irb/commit/b039b89343
2023-06-10 12:51:38 +00:00
Stan Lo 45ff2f4a89 [ruby/irb] Refactor ExtendCommand::Nop
(https://github.com/ruby/irb/pull/598)

* Rename conf to irb_context

* Drop Nop#irb method because it's only used by irb/ext/loader.rb

We don't need to expose this method to all command classes, especially
when it's just an alias of `irb_context.irb`.
2023-06-05 19:12:16 +00:00
Stan Lo 273b38475e [ruby/irb] Simplify irb_info command
(https://github.com/ruby/irb/pull/597)

https://github.com/ruby/irb/commit/0a0409c52b
2023-06-05 19:02:43 +00:00
ima1zumi 76ee4edb97 [ruby/irb] Fixed string escaping omissions
(https://github.com/ruby/irb/pull/599)

I received a `RegexpError` when I typed `::Array[`.
::Array[/Users/mi/ghq/github.com/ruby/irb/lib/irb/completion.rb:236:in `retrieve_completion_data': premature end of char-class: /^Array[/ (RegexpError)
2023-06-05 18:34:10 +00:00
Stan Lo 4275a8098e [ruby/irb] Bump version to 1.7.0
(https://github.com/ruby/irb/pull/596)

https://github.com/ruby/irb/commit/c2e7002867
2023-06-04 15:24:30 +00:00
tomoya ishida d5ef373b11 [ruby/irb] Set maximum document dialog height by
preferred_dialog_height provided by Reline
(https://github.com/ruby/irb/pull/591)

https://github.com/ruby/irb/commit/df6907aca9
2023-05-28 09:20:18 +00:00
TSUYUSATO Kitsune 92d6c9a7b1 [ruby/irb] Allow `show_source` for private methods
(https://github.com/ruby/irb/pull/589)

* Allow `show_source` for private methods

Fix https://github.com/ruby/irb/pull/577

* Pend tests on TruffleRuby

It seems `eval(..., __LINE__ + 1)` does not work.
Other similar tests are also pended on TruffleRuby, so I think it
is acceptable.

* Use `private_method_defined?` instead of `defined?`
2023-05-23 16:16:37 +00:00
tomoya ishida e8c9f727e8 [ruby/irb] Simplify each_top_level_statement
(https://github.com/ruby/irb/pull/576)

* Simplify each_top_level_statement, reduce instance vars

* Update lib/irb/ruby-lex.rb

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

* Remove unused ltype from TestRubyLex#check_state response

* Remove unnecessary const path of TerminateLineInput

* Combine duplicated code state check into method

---------

https://github.com/ruby/irb/commit/172453cec4

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-05-19 13:48:08 +00:00
Adam Daniels b54b388f2a [ruby/irb] Display mod key as `Option` on Darwin platforms
(https://github.com/ruby/irb/pull/584)

Check RUBY_PLATFORM for `darwin` and modify the mod key from `Alt` to
`Option`.
2023-05-19 01:33:32 +00:00
Stan Lo cfb7997353 [ruby/irb] Refactor RubyLex's input/io methods
(https://github.com/ruby/irb/pull/583)

1. Make `RubyLex#set_input` simply assign the input block. This matches
   the behavior of `RubyLex#set_prompt`.
2. Merge `RubyLex#set_input`'s IO configuration logic with `#set_auto_indent`
   into `#configure_io`.
2023-05-18 19:00:33 +00:00
Stan Lo b695f58d52 [ruby/irb] Print deprecation warning for `help` command
(https://github.com/ruby/irb/pull/567)

* Give show_doc its own command class

* Print deprecation warning for `help` command
2023-05-18 03:28:31 +00:00
Stan Lo e9930b51b2 [ruby/irb] Retire magic-file.rb
(https://github.com/ruby/irb/pull/574)

`MagicFile` was introduced around v0.9.6, which was like 14~15 years ago.
It was needed because back then we needed to read a file's magic comment
to determine the encoding of it, and read it with that encoding.

Commit: 3ee79e89

But now we expect files to be encoded in UTF-8 and don't specify encoding
through magic comments anymore, `MagicFile` can be retired.
2023-04-28 17:20:20 +00:00
Stan Lo 5cd4f35da6 [ruby/irb] Simplify Locale#load
(https://github.com/ruby/irb/pull/571)

* Simplify Locale#load

Instead of loading file content with `MagicFile` and then evaluting it,
we can just use `Kernel.load` to load the file.

* Remove unused optional argument

* Remove unused Locale#require and #toplevel_load
2023-04-27 15:42:21 +00:00
Stan Lo a58cae77f7 [ruby/irb] Stop using MagicFile for printing help messages
(https://github.com/ruby/irb/pull/573)

`MagicFile` was introduced around v0.9.6, which was like 14~15 years ago.
It was needed because back then we needed to read a file's magic comment
to determine the encoding of it, and read it with that encoding.

Commit: 3ee79e89ad

But now both EN and JA's help-message file are UTF-8 and have removed the
encoding comment, we don't need to open them with `MagicFile` anymore.
2023-04-27 11:07:05 +00:00
Stan Lo fe0b23b42f [ruby/irb] Remove encoding_aliases.rb
(https://github.com/ruby/irb/pull/569)

We don't have to load another file to define the legacy encoding aliases
map because there's only one definition of it. We can define it in
locale.rb directly.
2023-04-26 15:06:05 +00:00
Stan Lo 299d17a2f1
[ruby/irb] Fix Locale's encoding lookup for Japanese encodings
(https://github.com/ruby/irb/pull/568)

In 3ee79e89ad,
`encoding_aliases.rb` was introduced to return the correct encoding object for
`ujis` and `euc` encodings.

However, the return value of `@@legacy_encoding_alias_map[@encoding_name]`
is always overridden by a second look up with `Encoding.find(@encoding_name)`.
So the logic didn't work as expected.

This commit fixes the problem.
2023-04-26 13:13:25 +09:00
Stan Lo 73fc81199d [ruby/irb] Simplify the help command's implementation
(https://github.com/ruby/irb/pull/564)

The current method-redefining approach brings little benefit, makes it
harder to understand the code, and causes warnings like:

> warning: method redefined; discarding old execute

This patch simplifies it while displaying more helpful message when rdoc
couldn't be loaded.
2023-04-24 14:10:36 +00:00
Stan Lo 805899dda2 [ruby/irb] Filter out top-level methods when using `ls
<Class/Module>`
(https://github.com/ruby/irb/pull/562)

Instead of always printing methods inherited from Class or Module, IRB by
default should filter them out unless `<Class/Module>` is specified to be
either of those.
2023-04-24 14:05:16 +00:00
Yusuf Daniju ec211ad54d [ruby/irb] fix typo in tracer (https://github.com/ruby/irb/pull/565)
https://github.com/ruby/irb/commit/2f567f3d3e
2023-04-23 18:41:40 +00:00
ima1zumi f7c8d3bf96 [ruby/irb] Bump version to 1.6.4
(https://github.com/ruby/irb/pull/560)

https://github.com/ruby/irb/commit/01328da9b6
2023-04-09 13:44:12 +00:00
Stan Lo e7f77e1e89 [ruby/irb] Simplify command method definition
(https://github.com/ruby/irb/pull/559)

* Remove unnecessary command argument generation code

Now that all the supported Ruby versions handle splat args and splat kwargs,
we don't need that args generation code anymore.

* Remove unused command definition code

If we look at `@EXTEND_COMMANDS`, all commands are defined in a file, which
means the `if load_file` branch is always executed. Therefore we can drop
the else branch of that condition.

* Avoid defining unnecessary command methods

There's no need to define another command method just to call `Command.execute`.
2023-04-08 10:11:50 +00:00
Stan Lo 2f8e5c80e6 [ruby/irb] Drop Ruby 2.6 support
(https://github.com/ruby/irb/pull/555)

* Remove all Ruby 2.6 support

* Drop Ruby 2.6 specific testing conditions

* Only run Ruby 2.7+ on CI

* Bump Ruby requirement to 2.7+

https://github.com/ruby/irb/commit/3f714b616c
2023-04-05 21:40:40 +00:00
Stan Lo cd94bcdc46 [ruby/irb] Don't check RUBY_ENGINE when deciding whether to accept kargs
Ruby implementations like JRuby and TruffleRuby already indicate their
compatibility target with RUBY_VERSION. We don't need to exclude
them from accepting keyword arguments as long as they target 2.7+.

https://github.com/ruby/irb/commit/bf20faa4e6

Co-authored-by: Kevin Menard <kevin@nirvdrum.com>
2023-04-02 15:34:28 +00:00
Stan Lo f25791884c [ruby/irb] Remove dead code (https://github.com/ruby/irb/pull/554)
* Remove unused ATTR_TTY and ATTR_PLAIN constants

They were added in d7d26b51bf

But the references were removed in 1c76845cca

Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>

* Remove unused MethodExtender module

It was added in 6cc5d718d7
but it's not used anywhere.

Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>

* Remove unused IRB.irb_at_exit

It's not used after aaf4eb4e98

Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>

* Remove unused InputCompletor.ignored_modules

It was added in 88311ce3c8
but the reference was removed in 78c74d2425

* Remove unused TracerLoadError constant

This constant was added in cb50fa3738
but never referenced.

---------

https://github.com/ruby/irb/commit/7de0234325

Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
2023-04-02 14:11:12 +00:00
Stan Lo 309ff928f5 [ruby/irb] Replace METHOD_IS_A with ===
(https://github.com/ruby/irb/pull/542)

https://github.com/ruby/irb/commit/edd6c30e16
2023-03-13 18:11:58 +00:00
Stan Lo 1095baed34 [ruby/irb] Support inspecting BasicObject
(https://github.com/ruby/irb/pull/541)

https://github.com/ruby/irb/commit/1dc2a406a3
2023-03-13 14:31:37 +00:00
Stan Lo 56ebeba436 [ruby/irb] Bump version to 1.6.3
(https://github.com/ruby/irb/pull/537)

https://github.com/ruby/irb/commit/110e4a3219
2023-03-07 02:47:15 +00:00
tomoya ishida 0463c5806a [ruby/irb] Improve method completion for string and regexp that
includes word break characters
(https://github.com/ruby/irb/pull/523)

* Improve method completion for string and regexp that includes word break characters

* Remove completion-test's assert_not_include because candidates no longer include every possible methods

* Add comment about string's method completion regexp

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

* Add comment about regexp's method completion regexp

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

---------

https://github.com/ruby/irb/commit/aa8128c533

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-03-06 05:52:46 +00:00
Stan Lo 191e4ae33f [ruby/irb] Drop chained methods' completion support
(https://github.com/ruby/irb/pull/529)

Consider completion for this example: `foo.bar.b`

Without type information, it is hard to know the return value of the `bar`
method, so the current implementation interates through `ObjectSpace` to
get all possible candidates for the second method.

In small projects, the performance and accuracy are acceptable. But in
bigger projects, the performance is unacceptable and the accuracy is mostly
poor.

So this commit drops the support for chained methods' completion.
2023-03-04 15:34:49 +00:00
tomoya ishida b49053a6be [ruby/irb] Avoid slow symbol completion when completion target is an
empty symbol
(https://github.com/ruby/irb/pull/534)

https://github.com/ruby/irb/commit/35697f3ef3
2023-03-03 13:41:21 +00:00
Stan Lo da6ac30d1e [ruby/irb] Specify metadata to provide richer information on
rubygems.org
(https://github.com/ruby/irb/pull/532)

https://github.com/ruby/irb/commit/f01c2a6ac1
2023-03-02 13:49:03 +00:00
Stan Lo 9ddd73060b [ruby/irb] Display and prioritise instance methods in `ls
<module/class>`
(https://github.com/ruby/irb/pull/496)

https://github.com/ruby/irb/commit/e3d21f9329
2023-02-28 14:36:12 +00:00
Stan Lo ea830ab29d [ruby/irb] Add a comment about Rails' patch on
Workspace#filter_backtrace
(https://github.com/ruby/irb/pull/526)

* Add a comment about Rails' patch on Workspace#filter_backtrace

* Update lib/irb/workspace.rb

Co-authored-by: Sorah Fukumori <sora134@gmail.com>

---------

https://github.com/ruby/irb/commit/9443d911fc

Co-authored-by: Sorah Fukumori <sora134@gmail.com>
2023-02-27 15:23:31 +00:00
Stan Lo 0aa50a03b1 [ruby/irb] Provide more useful message when
`IRB::Inspector#inspect_value` errors
(https://github.com/ruby/irb/pull/511)

**Before**

```
irb(main):001:0> c = Cat.new "foo"
(Object doesn't support #inspect)
=>
```

**After**

```
irb(main):001:0> c = Cat.new "foo"
An error occurred when inspecting the object: #<NoMethodError: undefined method `is_a?' for foo:Cat

      if obj.is_a?(String)
            ^^^^^^>
Result of Kernel#inspect: #<Cat:0x0000000109090d80 @name="foo">
=>
```
2023-02-27 11:07:19 +00:00
ima1zumi 672b81b090 [ruby/irb] Remove unused Struct
(https://github.com/ruby/irb/pull/522)

https://github.com/ruby/irb/commit/97dae166ae
2023-02-25 16:50:33 +00:00
Stan Lo cbac0fa4cb [ruby/irb] Remove unused context argument from Worksapce#evaluate
(https://github.com/ruby/irb/pull/488)

The context argument was introduced in this change:

6806669d17 (diff-296327851fb7a2c307c2d0693b769f58c01aaf315972f290500d10081ee200a9)

perhaps for potential usages. But after that it's never used.
2023-02-18 11:34:28 +00:00
HASUMI Hitoshi 3a9d52466a [ruby/irb] Fix help-message (https://github.com/ruby/irb/pull/506)
https://github.com/ruby/irb/commit/a55ace0791
2023-02-15 14:53:33 +00:00
tomoya ishida f313514563 [ruby/irb] Fix colorize backtick symbol
(https://github.com/ruby/irb/pull/508)

https://github.com/ruby/irb/commit/dd7f25cd45

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-02-12 20:27:32 +00:00
Stan Lo cb9b885e78 [ruby/irb] Store context in RubyLex
Some background for this refactor:

1. Through a RubyLex instance's lifetime, the context passed to its methods
   should be the same.
   Given that `Context` is only initialised in `Irb#initialize`,
   this should be true.

2. When `RubyLex` is initialised, the context object should be accessible.
   This is also true in all 3 of `RubyLex.new`'s invocations.

With the above observations, we should be able to store the context in `RubyLex`
as an instance variable. And doing so will make `RubyLex`'s instance methods
easier to use and maintain.

https://github.com/ruby/irb/commit/5c8d3df2df
2023-01-14 09:19:09 +00:00
Stan Lo 207f8d0027 [ruby/irb] Avoid calling private methods on the main object
(https://github.com/ruby/irb/pull/498)

When the main object is frozen, `IRB` wraps a `SimpleDelegator` around it.
But because `SimpleDelegator` doesn't delegate private methods, methods like
`require_relative` or `const_get` would cause error, which are needed for
lazily loading commands.

This commit works around this limitation by avoiding those private method calls
when setting up command execution.
2023-01-12 11:49:16 +00:00
Stan Lo 019c65828b [ruby/irb] Remove redundant argument defaults from some RubyLex
methods
(https://github.com/ruby/irb/pull/502)

* Remove unnecessary parameter defaults

These methods are always called with tokens specified. So their default
`@tokens` value is never used and is misleading.

* Remove unnecessary context default

* Require tokens for `RubyLex#check_state`
2023-01-12 10:30:17 +00:00
Hiroshi SHIBATA 7e283c585e [ruby/irb] Formatting to header styles
https://github.com/ruby/irb/commit/cef125850d
2023-01-11 22:29:10 +00:00
Hiroshi SHIBATA 128398e7cd [ruby/irb] After Ruby 2.0, coding is always utf-8
https://github.com/ruby/irb/commit/7a94bc4135
2023-01-11 22:29:10 +00:00
Hiroshi SHIBATA c7bb8d67b7 [ruby/irb] Removed Release Version and Revisions for old VCS software
https://github.com/ruby/irb/commit/07fae94862
2023-01-11 22:29:09 +00:00
Stan Lo c693dfd7ef [ruby/irb] Drop unused arguments in `RubyLex`
(https://github.com/ruby/irb/pull/504)

* Simplify `RubyLex#set_prompt`

It's optional argument is never used by any caller.

* Remove the optional `p` argument from `RubyLex#set_input`

The argument is only used in a test case, which can be easily replaced by
a block argument.
2023-01-11 21:26:18 +00:00
Stan Lo 3d6500ee6e [ruby/irb] workspace.rb cleanup
(https://github.com/ruby/irb/pull/489)

* Remove unnecessary Binding#source_location check

`Binding#source_location` was added in 2.6, which is the minimum supported
version now. So this check is no longer necessary.

* Remove unused IRB.delete_caller

This method was added in the earliest version of IRB:

f47808999d

But it's not currently referenced by anything. We can verify this with a
org-wide search result:

https://github.com/search?q=org%3Aruby+delete_caller&type=code
2023-01-04 09:35:57 +00:00
tomoya ishida 34f8ca1714 [ruby/irb] Fix prompt and code mismatch
(https://github.com/ruby/irb/pull/386)

* fix prompt and code mismatch

* Add test for prompt and code mismatch bug

https://github.com/ruby/irb/commit/a5765d8177

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-01-02 19:25:11 +00:00
Mau Magnaguagno ec7e082906 [ruby/irb] Refactor RubyLex#process_literal_type
(https://github.com/ruby/irb/pull/350)

Simplify part of regex ``[_a-zA-Z0-9]`` with equivalent shorthand ``\w``.
Replace case-when with match ``$1`` or default value ``?"``, making intention more clear.
2022-12-27 17:05:32 +00:00
Hiroshi SHIBATA c09f342d04 [ruby/irb] Fix wrong conf path with XDG_CONFIG_HOME. It should be under the HOME directory, not current directory
https://github.com/ruby/irb/commit/33a5e55ffd
2022-12-27 00:09:12 +00:00
tompng 953d4c22ed [ruby/irb] fix indent depth calculation after heredoc and embdoc
https://github.com/ruby/irb/commit/b7973dd2d2
2022-12-26 13:03:07 -08:00
tompng f20aac5c59 [ruby/irb] fix auto-indent after multiline string
https://github.com/ruby/irb/commit/f65ec49684
2022-12-26 13:03:07 -08:00
Takashi Kokubun b2bf5d237b [ruby/irb] Version 1.6.2
https://github.com/ruby/irb/commit/a8ea9963c6
2022-12-20 09:07:55 -08:00
Takashi Kokubun cf0b413ef8 [ruby/irb] Respect DLEXT to force-load debug.so
(https://github.com/ruby/irb/pull/481)

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2022-12-20 09:07:54 -08:00
Takashi Kokubun a1dba60b5b [ruby/irb] Version 1.6.1
https://github.com/ruby/irb/commit/229476ba76
2022-12-13 18:36:45 +00:00
Stan Lo 223d4448c8 [ruby/irb] `show_doc` command should take non-string argument too
(https://github.com/ruby/irb/pull/478)

Given that `show_doc` already supports syntax like `String#gsub`, it
should be able to take it in non-string form too, like `edit` and
`show_source` do. This ensures users can have a consistent syntax on
argument between different commands.
2022-12-12 17:35:48 +00:00
Stan Lo 381e128c13 [ruby/irb] Fix step command (https://github.com/ruby/irb/pull/477)
The current `next` pre-command workaround on IRB source stepping
moves the location by 1 extra line. A better way is to make `debug`
skip IRB frames completely, which is what this commit does.

It also fixes the step command's test. The `|` in regexp was not escaped
so it was always incorrectly matched.
2022-12-09 23:39:17 +00:00
Takashi Kokubun 95b423f93a [ruby/irb] Version 1.6.0
https://github.com/ruby/irb/commit/d799c5c9da
2022-12-09 04:35:43 +00:00
Stan Lo c9076d546a [ruby/irb] Add show_doc as an alias to the help command
(https://github.com/ruby/irb/pull/475)

In the long-term, we want to align with `Pry`, `byebug` and `debug` to
use the `help` command to list all commands, which is what `show_cmds`
currently does. And `show_doc` will be the command to look up Ruby APIs.

By aliasing `show_doc` to the current `help` now, users will have time
to get use to it.
2022-12-08 21:46:55 +00:00
Stan Lo 12b7c129bf [ruby/irb] Gracefully handle missing command argument
(https://github.com/ruby/irb/pull/473)

* Handle file loading commands' argument error gracefully

Currently, if users don't provide an argument to `source`,
`irb_load`, and `irb_require`, IRB raises `ArgumentError` with full
stacktrace. This is confusing because it looks similar to when IRB has
internal issues. The message also isn't helpful on helping users avoid
the error.

So in this commit, I add a new `CommandArgumentError` for commands to
raise explicitly when users' input doesn't satisfy a command's argument
requirement.

* Gracefully handle `fg` command's argument requirement
2022-12-08 21:05:37 +00:00
Stan Lo 3956bb859c [ruby/irb] Add "show_cmds" command to list all commands'
descriptions
(https://github.com/ruby/irb/pull/463)

https://github.com/ruby/irb/commit/7e857655ac
2022-12-08 19:10:23 +00:00
Stan Lo a2d3f5606a [ruby/irb] Lazily load the multi-irb extension
(https://github.com/ruby/irb/pull/472)

* Lazily load the multi-irb extension

We now have plan to implement a command that prints all commands'
information, which will need to load all command files without actually
running them.

But because the `multi-irb` extension patches IRB's top-level methods,
loading it would cause unintentional side-effects.

So this commit moves related requires into command execution to avoid the problem.

* Make extend_irb_context private

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-12-07 23:30:00 +00:00
Stan Lo 9aa18f61f2 [ruby/irb] Allow disabling autocompletion with
`IRB_USE_AUTOCOMPLETE=false`
(https://github.com/ruby/irb/pull/469)

* Allow using IRB_USE_AUTOCOMPLETE=false to disable autocompletion

Currently, the only 2 ways to disable autocompletion are:

1. Create `.irbrc` and set `IRB.conf[:USE_AUTOCOMPLETE] = false`
2. Add the `--noautocomplete` flag when using the `irb` executable

Both of them are less convenient than setting a env var and are
lesser known to devs.

And given the number of problems the autocompletion has (see #445), I
think we should allow disabling it with a simple `IRB_USE_AUTOCOMPLETE=false`.

* Mention some env var configs in the README
2022-12-06 00:53:32 +00:00
Nobuyoshi Nakada d532d27507 [ruby/irb] Use class methods of `File` over `Kernel.open`
https://github.com/ruby/irb/commit/e0ec5e1bd8
2022-11-30 10:18:57 +00:00
Takashi Kokubun 9a84971315 [ruby/irb] Make sure ls doesn't return an array
(https://github.com/ruby/irb/pull/461)

https://github.com/ruby/irb/commit/367797bb05
2022-11-30 04:52:33 +00:00
Takashi Kokubun d13de3a62e [ruby/irb] Version 1.5.1
https://github.com/ruby/irb/commit/f9507923fa
2022-11-28 18:44:36 +00:00
Takashi Kokubun c5279db75f [ruby/irb] Fix the debug.gem force-loader for Ruby 3.2
(https://github.com/ruby/irb/pull/458)

* Fix the debug.gem force-loader for Ruby 3.2

* Support 1.7.0dev format as well
2022-11-28 18:42:59 +00:00
Takashi Kokubun c9fbc779a6 [ruby/irb] Add commands to start and use the debugger
(https://github.com/ruby/irb/pull/449)

* Seamlessly integrate a few debug commands

* Improve the break command support

* Utilize skip_src option if available

* Add step and delete commands

* Write end-to-end tests for each debugger command

* Add documentation

* Add backtrace, info, catch commands

https://github.com/ruby/irb/commit/976100c1c2
2022-11-21 08:46:27 +00:00
Takashi Kokubun 509f04ca91 [ruby/irb] Version 1.5.0
Asked by ko1 to release https://github.com/ruby/irb/pull/444 for
simplifying https://github.com/ruby/debug/pull/808,
and hsbt made me a gem owner for this.

Stan said 1.4.3 should have been 1.5.0, but now that it's already
released and it's not worth yanking it, we're not doing that change.
However, now that this release includes `debug` and `edit`, I think it's
a good opportunity to hit the version 1.5.0.

https://github.com/ruby/irb/commit/85937d71f6
2022-11-20 21:24:25 -08:00
Stan Lo 180ed611b2 [ruby/irb] Add edit command (https://github.com/ruby/irb/pull/453)
* Add edit command

* Make find_source a public singleton method

* Add document for the edit command

* Make find_end private

* Remove duplicated private

https://github.com/ruby/irb/commit/4321674aa7
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-11-20 04:47:54 +00:00
Takashi Kokubun 5958c305e5 [ruby/irb] Document a full list of commands
(https://github.com/ruby/irb/pull/451)

* Document a full list of commands

* Document debug as well

* Make it less duplicated
2022-11-19 22:14:44 +00:00
Takashi Kokubun ba3b40a9ae [ruby/irb] Discover and load debug.gem even if it's not in Gemfile
(https://github.com/ruby/irb/pull/448)

* Minor fixes on debug command

* Discover and load debug.gem even if it's not in Gemfile

* Eliminate else for rescue

* Discover the latest one from all gem paths
2022-11-18 18:03:33 +00:00
Takashi Kokubun b1cbc883f2 [ruby/irb] Minor fixes on debug command
(https://github.com/ruby/irb/pull/447)

* Minor fixes on debug command

* Update lib/irb/cmd/debug.rb
2022-11-18 17:34:42 +00:00
Stan Lo 00872d120b [ruby/irb] Add debug command (https://github.com/ruby/irb/pull/446)
https://github.com/ruby/irb/commit/30faa13fa3
2022-11-18 09:11:23 +00:00
Hiroshi SHIBATA c76909e551 [ruby/irb] Bump up 1.4.3
https://github.com/ruby/irb/commit/1bddbbf602
2022-11-17 04:52:50 +00:00
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

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/478f19f3ae
2022-11-15 10:08:30 +00:00
st0012 34320d883f [ruby/irb] Deprecate reidline flags
https://github.com/ruby/irb/commit/9957e83f7d
2022-11-15 10:08:29 +00:00
st0012 4f348e482c [ruby/irb] Rename leftover Reidline references
https://github.com/ruby/irb/commit/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)

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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)


https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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
https://github.com/ruby/irb/commit/ee9b33c817
2022-10-08 03:17:42 +09:00
st0012 7cafe09aec [ruby/irb] Lazily evaluate candidates locals
https://github.com/ruby/irb/commit/19a2fcbd87
2022-10-08 03:17:42 +09:00
Imir Kiyamov 83a6213f31 [ruby/irb] Fixed sort of variables in completion
https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/64d6a461d5
2022-10-05 19:15:28 +09:00
Hiroshi SHIBATA 2f6a263787 [ruby/irb] Use USE_REIDLINE for backword compatibility
https://github.com/ruby/irb/commit/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.).

https://github.com/ruby/irb/commit/5bcade7130
2022-10-05 17:14:19 +09:00
st0012 203b831065 [ruby/irb] Bump version to 1.4.2
https://github.com/ruby/irb/commit/f9960dbd37
2022-10-05 15:25:02 +09:00
Hiroshi SHIBATA f081bba875 [ruby/irb] Added aycabta to authors
https://github.com/ruby/irb/commit/a6bfa7b2e6
2022-10-05 15:15:33 +09:00
st0012 10e830c25b [ruby/irb] Remove unused error
https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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

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

https://github.com/ruby/irb/commit/0e760d2674
2022-10-03 04:59:51 +09:00
st0012 42fcbcc215 [ruby/irb] Remove unnecessary condition
https://github.com/ruby/irb/commit/daffb8bfe5
2022-10-03 04:59:50 +09:00
st0012 55e2116f2c [ruby/irb] Refactor ripper_lex_without_warning
https://github.com/ruby/irb/commit/0db0a8ddc5
2022-10-03 04:59:49 +09:00
tompng 641310ce37 [ruby/irb] Fix ripper_lex_without_warning duplicated heredoc token
https://github.com/ruby/irb/commit/45b539af39
2022-10-01 04:17:15 +09:00
tompng 369f1668cd [ruby/irb] Rewrite on_scan proc to be more readable.
https://github.com/ruby/irb/commit/da54e7f081
2022-09-22 00:37:40 +09:00
tompng 9f68687879 [ruby/irb] Scan every single characters in IRB::Color.scan
https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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]

https://github.com/ruby/irb/commit/4192683ba2
2022-09-17 02:25:26 +09:00
Nobuyoshi Nakada f863bc505c [ruby/irb] Fix the error when LC_MESSAGES config value is nil
https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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 https://github.com/ruby/irb/commit/5f749c613c89.

https://github.com/ruby/irb/commit/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 https://github.com/ruby/irb/commit/026700499dfd,
but it seems that this is just be mistake, otherwise the later handling
of `LoadError` would not be needed.

https://github.com/ruby/irb/commit/54c8df06ff
2022-08-23 18:01:35 +09:00
tompng b54f26b704 [ruby/irb] shortcut colorize_code to speedup pretty_print
https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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)
https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/d54b271984
2022-01-27 01:28:52 +09:00
st0012 e53962b9e1 [ruby/irb] Use require_relative to load extensions/commands
https://github.com/ruby/irb/commit/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`.

https://github.com/ruby/irb/commit/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)
https://github.com/ruby/irb/commit/1c03bd3373
2021-12-29 09:37:05 +09:00
aycabta 0f1fbc6421 [ruby/irb] Version 1.4.1
https://github.com/ruby/irb/commit/b1d9c34441
2021-12-25 12:57:28 +09:00
aycabta ddf0cdee4f [ruby/irb] Support showing doc by dialog in iTerm2
https://github.com/ruby/irb/commit/a4b95d6634
2021-12-25 12:56:40 +09:00
aycabta 90239c4163 [ruby/irb] Version 1.4.0
https://github.com/ruby/irb/commit/b80ec5821e
2021-12-25 00:41:04 +09:00
aycabta 214b6128ae [ruby/irb] Update dependency, reline >= 0.3.0
https://github.com/ruby/irb/commit/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

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

https://github.com/ruby/irb/commit/f80971994a
2021-12-24 10:32:14 +09:00
aycabta b96ef7684c [ruby/irb] Add East Asian Ambiguous Width to irb_info command
https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/619aecb412
2021-10-13 06:33:48 +09:00
aycabta 7732052718 [ruby/irb] Add help about extra doc dir option
https://github.com/ruby/irb/commit/5018f2cb99
2021-10-11 21:12:58 +09:00
aycabta 866a09dd9e [ruby/irb] Add --extra-doc-dir option to show doc dialog
https://github.com/ruby/irb/commit/3f79cb506f
2021-10-11 21:12:57 +09:00
aycabta dcaaf79ca0 [ruby/irb] Add periods to doc
https://github.com/ruby/irb/commit/6330601629
2021-10-11 20:34:18 +09:00
aycabta 340fabca2c [ruby/irb] Set default return_format
https://github.com/ruby/irb/commit/7ee15bc668
2021-10-11 15:39:48 +09:00
Takashi Kokubun cf74755921 [ruby/irb] Revert "Optimize show_source command further"
This reverts commit 27dd2867cda5c789efaa5078214ad2fd82adcebf.

This is to fix the test I added.

(I separated commits to test a new behavior of ruby-commit-hook)

https://github.com/ruby/irb/commit/fe055d521a
2021-10-10 23:23:18 -07:00
aycabta 5805b1472a [ruby/irb] Version 1.3.8.pre.11
https://github.com/ruby/irb/commit/49b9f644c2
2021-10-09 23:29:29 +09:00
aycabta 98d9a7e435 [ruby/irb] Update dependency, reline >= 0.2.8.pre.11
https://github.com/ruby/irb/commit/4f686afbca
2021-10-09 23:29:24 +09:00
aycabta 1507cb084c [ruby/irb] Determine left and right when the width of either side is zero correctly
https://github.com/ruby/irb/commit/5df6e1f027
2021-10-08 10:34:06 +09:00
aycabta 576eccf76d [ruby/irb] Calculate right side doc dialog width correctly
https://github.com/ruby/irb/commit/f34da7fa04
2021-10-08 10:33:56 +09:00
aycabta 374efa8e30 [ruby/irb] Specify whether to show the doc dialog on the left or right side by using variable names
https://github.com/ruby/irb/commit/a23a88b8c9
2021-10-08 10:33:47 +09:00
aycabta 5c02df8296 [ruby/irb] Display doc dialog in gaps on narrow screen
https://github.com/ruby/irb/commit/4d7cefcaa4
2021-10-08 10:33:39 +09:00
Kaíque Kandy Koga 80e2242da6 [ruby/irb] Update descriptions of methods
From Reidline to Reline

Update description used in take_corresponding_syntax_to_kw_do and is_the_in_correspond_to_a_for methods

Use possessive noun correctly

Second element

https://github.com/ruby/irb/commit/4fa9714d6f
2021-10-07 23:55:54 +09:00
Jeremy Evans 896626fa02 [ruby/irb] Make IRB::Context#exit call super if UncaughtThrowError
Fixes calling exit after binding.irb.

Fixes [Bug #18234]

https://github.com/ruby/irb/commit/4ea8d376f2
2021-10-07 23:53:58 +09:00
Masataka Pocke Kuwabara 853ca5cceb [ruby/irb] Remove `require` in signal handler to avoid ThreadError
`rdoc` has been required so it looks unnecessary

https://github.com/ruby/irb/commit/5f749c613c
2021-10-03 21:51:54 +09:00
aycabta 208b7b8199 [ruby/irb] Version 1.3.8.pre.10
https://github.com/ruby/irb/commit/15bcbbb284
2021-10-03 21:50:30 +09:00
aycabta a5c58e88de [ruby/irb] Update dependency, reline >= 0.2.8.pre.10
https://github.com/ruby/irb/commit/800e83eabd
2021-10-03 21:50:26 +09:00
aycabta 00cfafc0f5 [ruby/irb] Add doc about "echo on assignment"
https://github.com/ruby/irb/commit/5af637b3c1
2021-09-27 03:23:48 +09:00