Commit graph

833 commits

Author SHA1 Message Date
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
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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

c2e7002867
2023-06-04 15:24:30 +00:00