Commit graph

855 commits

Author SHA1 Message Date
tomoya ishida
db7a4be846 [ruby/irb] Easter egg for autocomplete mode
(https://github.com/ruby/irb/pull/737)

* Show easter-egg inside document dialog in autocomplete mode

* Show more easter_egg(dancing or logo) when Alt+d is pressed in autocomplete mode

a8e5cc7354
2023-10-28 14:47:46 +00:00
Stan Lo
745879b5ed [ruby/irb] Minor refactors around irb.rb
(https://github.com/ruby/irb/pull/736)

* Remove dead method

* Simplify IRB.version

* Move private Irb methods together

* Centralise @CONF initialization/assignment in init.rb

* Move attr_* calls above initialize method

cf23be4395
2023-10-21 18:06:00 +00:00
tomoya ishida
177d8ee056 [ruby/irb] Bump version to 1.8.3
(https://github.com/ruby/irb/pull/731)

de79375ac1
2023-10-14 14:42:37 +00:00
tomoya ishida
4e5c505bad [ruby/irb] Restore IRB::InputCompletor for compatibility
(https://github.com/ruby/irb/pull/730)

77265efc5f
2023-10-14 14:12:43 +00:00
Stan Lo
3aba21511b [ruby/irb] Bump version to 1.8.2
47693a2213
2023-10-12 21:36:13 +00:00
tomoya ishida
1126bd8c65 [ruby/irb] Fix require path completion disturbing string method
completion
(https://github.com/ruby/irb/pull/726)

e42dc74ce0
2023-10-12 16:54:09 +00:00
tomoya ishida
cf21c72cdb [ruby/irb] Fix test runner exit bug
(https://github.com/ruby/irb/pull/728)

* Remove useless test setup and teardown that sets MAIN_CONTEXT to nil

* Avoid adding command methods to main object in test

f204829a08
2023-10-12 13:55:47 +00:00
tomoya ishida
e029375a7d [ruby/irb] Decouple RubyLex from prompt and line_no
(https://github.com/ruby/irb/pull/701)

* Remove instance variable prompt and line_no from RubyLex

* Fix prompt test

* Rename prompt generating method and make it private

1ceb97fe2e
2023-10-12 12:53:31 +00:00
Takashi Kokubun
5140e6a4c3 Fix calling exit if irb_context is nil
Trying to avoid a flaky failure like:
1761611381
2023-10-11 16:22:20 -07:00
tomoya ishida
94cb5765e2 [ruby/irb] Rename current completor to RegexpCompletor and
refactored for future extension
(https://github.com/ruby/irb/pull/707)

* Move completion implementation to completion/regexp_completor for future extension

* Remove constant CompletionProc and PerfectMatchedProc and add a class method

* Move document display logic to InputCompletor. Each completor only need to implement `completion_caididates` and `doc_namespace`

* Move display_document logic to RelineInputMethod

* Use RegexpCompletor directly. Not through class method of InputCompletor.

* RegexpCompletor extends BaseCompletor, move back definition to completion.rb

* Move display_document test to input_method test

* Stop re-initialize completor on each completion phase

* Store completor to ReadlineInputMethod's iver

1e98521483
2023-10-11 17:09:05 +00:00
Stan Lo
cc311e1c45 [ruby/irb] Avoid locking the debug UI to a single thread
(https://github.com/ruby/irb/pull/725)

Since `debug` stores and updates the target thread via its Session's
`@tc` variable, we don't need to and shouldn't lock the UI to the thread
that activates the integration.

202efdbf0c
2023-10-11 14:16:39 +00:00
Stan Lo
b43cc51dca [ruby/irb] Clear all context usages in RubyLex
(https://github.com/ruby/irb/pull/684)

After this change, `RubyLex` will not interact with `Context` directly
in any way. This decoupling has a few benefits:

- It makes `RubyLex` easier to test as it no longer has a dependency on
  `Context`. We can see this from the removal of `build_context` from
  `test_ruby_lex.rb`.
- It will make `RubyLex` easier to understand as it will not be affected
  by state changes in `Context` objects.
- It allows `RubyLex` to be used in places where `Context` is not available.

d5b262a076
2023-10-04 12:13:33 +00:00
Stan Lo
f59b488b5a [ruby/irb] Page show_source's output
(https://github.com/ruby/irb/pull/719)

3cedc5cb62
2023-09-22 13:00:32 +00:00
Chad Schroeder
a8afedce6d [ruby/irb] Handle Concurrent Sessions and Saving Readline::HISTORY
(https://github.com/ruby/irb/pull/651)

* handle concurrent sessions and saving Readline::HISTORY, fixes https://github.com/ruby/irb/pull/510

* separate tests

* don't mutate the HISTORY object on the class

* avoid repeated .to_i calls

* remove intermediary history array

* work with array, fix test comment

---------

1681ada328

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-09-16 12:48:32 +00:00
Stan Lo
d83b5ea09d [ruby/irb] Bump version to 1.8.1
(https://github.com/ruby/irb/pull/706)

c7c838a4bf
2023-09-05 13:42:21 +00:00
Stan Lo
3678734fac [ruby/irb] Drop rdoc's version requirement
(https://github.com/ruby/irb/pull/704)

1. The newer versions of rdoc requires pysch 4.0+, which could break apps
   using Ruby 3.0 or 2.7. #703 has more detailed explanation on this.
2. We actually don't use any version-specific rdoc APIs. So having a version
    requirement is not necessary atm.

3e6ba78c42
2023-08-31 15:44:17 +00:00
Stan Lo
8804a70387 [ruby/irb] Require Reline 0.3.8+
(https://github.com/ruby/irb/pull/702)

Reline 0.3.8 reduces the chance of having a deadlock with the debugger
while using the new `irb:rdbg` integration.

9b8c56b7d4
2023-08-31 14:08:08 +00:00
Stan Lo
36a3899e9d [ruby/irb] Bump version to 1.8.0
(https://github.com/ruby/irb/pull/700)

a061744ed3
2023-08-30 09:17:06 +00:00
Stan Lo
f37f357e80 [ruby/irb] Improve help/show_cmds message during debugger
integration
(https://github.com/ruby/irb/pull/693)

* `help` should display debugger's help during irb:rdbg session

* Update `show_cmds`'s output when in irb:rdbg session

4029c2e564
2023-08-29 18:36:16 +00:00
Stan Lo
6ed1a504d4 [ruby/irb] irb:rdbg cleanups (https://github.com/ruby/irb/pull/697)
* Remove unused method and constant from IRB::Debug

* Update comments

98914a963c
2023-08-29 12:54:25 +00:00
Stan Lo
221c2d0e19
[ruby/irb] Print deprecation message for prompt_n methods
(https://github.com/ruby/irb/pull/691)

They were removed in #685, but we should still keep them to avoid breaking
changes to tools like Chef.

533ff08947/lib/chef/shell.rb (L138)

b585e0c835
2023-08-29 18:15:05 +09:00
Summer ☀️
0cd92819c9
[ruby/irb] Remove unused PROMPT_N
(https://github.com/ruby/irb/pull/685)

66e69fa0dc
2023-08-29 18:15:05 +09:00
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.

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

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.

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

---------

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

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.

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`.

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 420e7d2270.

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

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.

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)

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`.

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)

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.

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

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

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.

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

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

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

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>`

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.

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)

18bb4022a9
2023-07-15 18:12:05 +00:00
ima1zumi
7ffb995f5e [ruby/irb] Bump 1.7.4 (https://github.com/ruby/irb/pull/645)
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`.

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)

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.

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)

85d6b4d146
2023-07-11 16:30:34 +00:00