Commit graph

924 commits

Author SHA1 Message Date
Stan Lo
57ca5960ad [ruby/irb] Restructure workspace management
(https://github.com/ruby/irb/pull/888)

* Remove dead irb_level method

* Restructure workspace management

Currently, workspace is an attribute of IRB::Context in most use cases.
But when some workspace commands are used, like `pushws` or `popws`, a
workspace will be created and used along side with the original workspace
attribute.

This complexity is not necessary and will prevent us from expanding
multi-workspace support in the future.

So this commit introduces a @workspace_stack ivar to IRB::Context so IRB
can have a more natural way to manage workspaces.

* Fix pushws without args

* Always display workspace stack after related commands are used

61560b99b3
2024-03-01 15:51:29 +00:00
Stan Lo
c976cb52a2 [ruby/irb] Add help messages to show_source and show_doc
commands
(https://github.com/ruby/irb/pull/887)

* Add help message to the show_source command

* Add help message to the show_doc command

06f43aadb3
2024-02-25 15:22:33 +00:00
Stan Lo
898f30f8bd [ruby/irb] Refactor IRB::Context#prompting
(https://github.com/ruby/irb/pull/889)

7b323ee514
2024-02-25 15:21:00 +00:00
tomoya ishida
ea2fb7460e [ruby/irb] Remove useless loaded file check
(https://github.com/ruby/irb/pull/885)

f6d489658e
2024-02-23 13:11:20 +00:00
tomoya ishida
598b03648f [ruby/irb] Remove remaining frozen_string_literal: false in lib/
(https://github.com/ruby/irb/pull/883)

4bfdb23ae6
2024-02-23 12:32:50 +00:00
Stan Lo
4831bb5bab [ruby/irb] Turn on frozen literal in files
(https://github.com/ruby/irb/pull/881)

83d90550c2
2024-02-23 10:53:53 +00:00
Stan Lo
37dde6e2f8 [ruby/irb] Unroll extension method generation
(https://github.com/ruby/irb/pull/882)

* Unroll extension method generation

Given we only have 2 remaining extension setter methods, both of which
only take 1 argument and don't have any alias, the current method generation
logic is overly complicated.

This commit simplifies the method generation logic by simply defining
the methods directly in the `IRB::Context` class.

* Fix use_loader extension

67eba5401b
2024-02-23 10:02:19 +00:00
tomoya ishida
88431c47ba [ruby/irb] Delete IRB::NotImplementedError
(https://github.com/ruby/irb/pull/878)

6751778948
2024-02-22 13:16:46 +00:00
Stan Lo
7e577e150a [ruby/irb] Fix irb:rdbg for ruby head
(https://github.com/ruby/irb/pull/876)

* Update binding.irb check for Ruby head

With https://github.com/ruby/ruby/pull/9605, backtrace in Ruby head
now has a new format. This commit updates the check for binding.irb
to work with Ruby head.

* Do not include a backtick in error messages and backtraces

[Feature #16495]

---------

ebffd3d976

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
2024-02-19 11:01:30 +09:00
Stan Lo
07c774e85c [ruby/irb] Revamp help command
(https://github.com/ruby/irb/pull/877)

* Make help command display help for individual commands

Usage: `help [command]`

If the command is not specified, it will display a list of all available commands.

If the command is specified, it will display the banner OR description of the command.

If the command is not found, it will display a message saying that the command is not found.

* Rename test/irb/cmd to test/irb/command

* Add banner to edit and ls commands

* Promote help command in the help message

1. Make `show_cmds` an alias of `help` so it's not displayed in the help message
2. Update description of the help command to reflect `help <command>` syntax

* Rename banner to help_message

43a2c99f3f
2024-02-18 18:21:08 +00:00
Stan Lo
f5801e2bf4 [ruby/irb] Standardize command related names
(https://github.com/ruby/irb/pull/873)

* Replace ExtendCommand with Command and standardize command related names

1. Rename lib/irb/extend-command.rb to lib/irb/command.rb
2. Rename lib/irb/cmd/*.rb to lib/irb/command/*.rb
3. Rename test/irb/test_cmd.rb to test/irb/test_command.rb
4. Rename ExtendCommand to Command

* Alias ExtendCommand to Command and deprecate it

* Rename Command::Nop to Command::Base

* Not deprecate old constants just yet

* Add lib/irb/cmd/nop.rb back

462c1284af
2024-02-16 16:47:36 +00:00
Stan Lo
b315826377 [ruby/irb] Support repeating debugger input by passing empty input
to it
(https://github.com/ruby/irb/pull/856)

* Test IRB's behaviour with empty input

* Handle empty input and pass it to debugger

Since `rdbg` accepts empty input to repeat the previous command, IRB
should take empty input in `irb:rdbg` sessions and pass them to the
debugger.

Currently, IRB simply ignores empty input and does nothing. This commit
creates `EmptyInput` to represent empty input so it can fit into the
current IRB's input processing flow in `Irb#eval_input`.

0e9db419be
2024-02-16 16:12:54 +00:00
Stan Lo
c84581f1d9 [ruby/irb] Repurpose the help command to display the help message
(https://github.com/ruby/irb/pull/872)

See #787 for more details.

d9192d92d0
2024-02-14 13:47:45 +00:00
tomoya ishida
d0412599e0 [ruby/irb] Improve constant lookup in SourceFinder
(https://github.com/ruby/irb/pull/871)

87c279ccf2
2024-02-14 13:46:49 +00:00
Stan Lo
2f0f95235a [ruby/irb] Fix SourceFinder's constant evaluation issue
(https://github.com/ruby/irb/pull/869)

Currently, if the signature's constant part is not defined, a NameError
would be raised.

```
irb(main):001> show_source Foo
(eval):1:in `<top (required)>': uninitialized constant Foo (NameError)

Foo
^^^
        from (irb):1:in `<main>'
```

This commit fixes the issue and simplifies the `edit` command's implementation.

8c16e029d1
2024-02-13 13:36:32 +00:00
Stan Lo
ec26786b1a [ruby/irb] Refactor eval_path and SourceFinder::Source
(https://github.com/ruby/irb/pull/870)

* Assign `@eval_path` through `irb_path=` method

This simplifies the original caching logic for the `eval_path` method
and makes it easier to understand.

* Refactor SourceFinder::Source

c63e4c4035
2024-02-13 13:33:36 +00:00
tomoya ishida
7af97dc71f [ruby/irb] Powerup show_source by enabling RubyVM.keep_script_lines
(https://github.com/ruby/irb/pull/862)

* Powerup show_source by enabling RubyVM.keep_script_lines

* Add file_content field to avoid reading file twice while show_source

* Change path passed to eval, don't change irb_path.

* Encapsulate source coloring logic and binary file check insode class Source

* Add edit command testcase when irb_path does not exist

* Memoize irb_path existence to reduce file existence check calculating eval_path

239683a937
2024-02-12 18:38:30 +00:00
tomoya ishida
06995eb45b [ruby/irb] Fix exit! command warning and method behavior
(https://github.com/ruby/irb/pull/868)

* Fix exit! command warning and method behavior

* Remove arg(0) from Kernel.exit and Kernel.exit!

372bc59bf5
2024-02-12 11:28:54 +00:00
Stan Lo
5c4657f883 [ruby/irb] Polish the exit! command and its tests
(https://github.com/ruby/irb/pull/867)

* Remove IRB.irb_exit! method

It's not necessary to introduce a new method just for the exit! command
at this moment.

* Rename ExitForcedAction to ForceExit

* Move force exit tests to a dedicated file

* Fix nested history saving with exit! command

Because we switched to use `Kernel#exit` instead of `exit!`, the outer
session's ensure block in `Irb#run` will be run, which will save the
history. This means the separate check to save history when force exiting
is no longer necessary.

* execute_lines helper should also capture IRB setup's output

This prevents setup warnings from being printed to test output
while allowing those output to be tested.

* Update readme

899d10ade1
2024-02-11 05:17:40 +00:00
Ignacio Chiazzo Cardarello
429eeb09f2 [ruby/irb] Introduce exit! command
(https://github.com/ruby/irb/pull/851)

* Added failing test for when writing history on exit

* Save history on exit

* Exit early when calling Kernel.exit

* use status 0 for kernel.exit

* Added test for nested sessions

* Update lib/irb.rb

---------

c0a5f31679

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-02-10 22:07:53 +00:00
Stan Lo
0b7f516834 [ruby/irb] Bump version to v1.11.2
(https://github.com/ruby/irb/pull/865)

afe1f459cc
2024-02-07 16:57:33 +00:00
Stan Lo
5f4245e74b [ruby/irb] Polish tracer integration and tests
(https://github.com/ruby/irb/pull/864)

* Remove useless ivar

* Simplify tracer test setup

* Treat tracer like a normal development dependency

* Only require ext/tracer when value is truthy

* Make tracer integration skip IRB traces

a97a4129a7
2024-02-07 14:59:10 +00:00
Nuno Silva
300dee1fe8 [ruby/irb] Fix usage of tracer gem and add tests
(https://github.com/ruby/irb/pull/857)

The new tests are skipped when ruby below 3.1, as it was a default gem on it, and in a version we do not support.

This also move definition of `use_tracer` to module Context instead of monkey patch.

08834fbd5f
2024-02-06 16:46:50 +00:00
Stan Lo
5d646fa136 [ruby/irb] Require pathname (https://github.com/ruby/irb/pull/860)
0ab96ed426
2024-02-02 22:25:33 +00:00
Ignacio Chiazzo Cardarello
aa780a678e [ruby/irb] Add a warning for when the history path doesn't exist
(https://github.com/ruby/irb/pull/852)

* Add a warning for when the history path doesn't exist

* warn when the directory does not exist

* added test for when the history_file does not exist

* Update lib/irb/history.rb

---------

9e6fa67212

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-02-02 21:58:22 +00:00
Stan Lo
ef427123ad [ruby/irb] Add rubocop with a few basic styling rules
(https://github.com/ruby/irb/pull/849)

* Use rubocop to enforce a few styling rules

* Add a CI job for linting

4f60cd88bb
2024-02-01 17:46:02 +00:00
Stan Lo
f36c61d27f [ruby/irb] Reset history counter even when @loaded_history_lines is
not defined
(https://github.com/ruby/irb/pull/853)

The issue (https://github.com/ruby/debug/issues/1064) is caused by a
combination of factors:

1. When user starts an IRB session without a history file, the
   `@loaded_history_lines` ivar is not defined.
2. If the user then starts the `irb:rdbg` session, the history counter
   is not set, because the `@loaded_history_lines` is not defined.
3. Because `irb:rdbg` saves the history before passing Ruby expression
   to the debugger, it saves the history with duplicated lines. The number
   grows in exponential order.
4. When the user exits the `irb:rdbg` session, the history file could be
   bloated with duplicated lines.

This commit fixes the issue by resetting the history counter even when
`@loaded_history_lines` is not defined.

4afc98c258
2024-02-01 16:19:07 +00:00
Nuno Silva
1236a74023 [ruby/irb] Skip re-setup when creating a child session
(https://github.com/ruby/irb/pull/850)

06b2d00dd3
2024-02-01 12:12:06 +00:00
tomoya ishida
fd44b42fb3 [ruby/irb] Fix undef and alias indent
(https://github.com/ruby/irb/pull/838)

a641746b18
2024-01-30 12:55:47 +00:00
ydah
0334115628 [ruby/irb] Synatx ==> Syntax
2ffacaa031
2024-01-25 09:58:17 +00:00
ydah
fd9b968569 [ruby/irb] recever ==> receiver
dbd0e368c4
2024-01-25 09:58:15 +00:00
ydah
6580a95f8d [ruby/irb] inifinity ==> infinity
78dea58000
2024-01-25 09:58:15 +00:00
Stan Lo
b2ec4308d6
[ruby/irb] Bump version to v1.11.1
(https://github.com/ruby/irb/pull/837)

f052097c4b
2024-01-19 10:49:12 +09:00
Stan Lo
8f4eda5092 [ruby/irb] Make SourceFinder ignore binary sources
(https://github.com/ruby/irb/pull/836)

73b35bb7f4
2024-01-08 12:42:39 +00:00
Stan Lo
4bdfc9070c [ruby/irb] Refactor exit command
(https://github.com/ruby/irb/pull/835)

* Remove unnecessary code from the exit command's implementation

1. The parameters of `IRB.irb_exit` were never used. But there are some
   libraries seem to call it with arguments + it's declared on the top-level
   IRB constant. So I changed the params to anonymous splat instead of removing them.
2. `Context#exit` was completely unnecessary as `IRB.irb_exit` doesn't use
   the `@irb` instance it passes. And since it's (or should be treated as)
   a private method, I simply removed it.
3. The `exit` command doesn't use the status argument it receives at all.
   But to avoid raising errors on usages like `exit 1`, I changed the argument to
   anonymous splat instead removing it.

* Make exit an actual command

* Update readme

452b543a65
2024-01-06 17:15:16 +00:00
Stan Lo
3dac27897e [ruby/irb] Require Reline v0.4.2+
(https://github.com/ruby/irb/pull/834)

eff8d0d46a
2024-01-06 12:16:12 +00:00
Stan Lo
66e0d92de5 [ruby/irb] Avoid completing empty input
(https://github.com/ruby/irb/pull/832)

The candidate list for empty input is all methods + all variables +
all constants + all keywords. It's a long list that is not useful.

812dc2df7b
2024-01-03 13:47:51 +00:00
Stan Lo
676748abca [ruby/irb] Make show_source resolve top-level constant names
(https://github.com/ruby/irb/pull/831)

5843616c78
2024-01-01 17:40:38 +00:00
tomoya ishida
c0e3c3b6fe [ruby/irb] Fix display_document params in noautocomplete mode
(https://github.com/ruby/irb/pull/826)

* Fix display_document params in noautocomplete mode

* Fix wrong preposing and target order in display_document

The fixed wrong-ordered value is not used in RegexpCompletor, so this change does not affect the test.

08208adb5e
2024-01-01 13:57:15 +00:00
Stan Lo
31959f1f13 [ruby/irb] Bump version to v1.11.0
(https://github.com/ruby/irb/pull/818)

7421359b92
2023-12-20 19:11:02 +09:00
Stan Lo
2793a30b69 [ruby/irb] Warn users about errors in loading RC files
(https://github.com/ruby/irb/pull/817)

1. Because `IRB.rc_file` always generates an rc file name, even if the
   file doesn't exist, we should check the file exists before trying to
   load it.
2. If any type of errors occur while loading the rc file, we should
   warn the user about it.

37ffdc6b19
2023-12-20 19:11:01 +09:00
tomoya ishida
745ab3e4c7 [ruby/irb] Warn and do nothing if block is passed to measure command
(https://github.com/ruby/irb/pull/813)

e79a90a1e6
2023-12-13 11:06:26 +00:00
Burdette Lamar
35990cb38c [ruby/irb] [DOC] RDoc for module IRB
(https://github.com/ruby/irb/pull/738)

[DOC] RDoc for module IRB

f3a0626298
2023-12-12 10:34:38 +00:00
Stan Lo
130268e264 [ruby/irb] Simplify show_source's super calculation
(https://github.com/ruby/irb/pull/807)

2cccc448de
2023-12-10 04:21:46 +00:00
Stan Lo
5809b75019 [ruby/irb] Debugging command warning should not be specific to the
`debug` command
(https://github.com/ruby/irb/pull/806)

b7b57311cc
2023-12-07 16:09:15 +00:00
Stan Lo
b29ed63883 [ruby/irb] Bump version to v1.10.1
(https://github.com/ruby/irb/pull/801)

a1e431bd83
2023-12-05 16:34:19 +00:00
Stan Lo
f55746a93d [ruby/irb] Disable pager when TERM is not set too
(https://github.com/ruby/irb/pull/802)

173980974b
2023-12-05 16:32:13 +00:00
Stan Lo
ef387e6730 [ruby/irb] Pager should be disabled when TERM=dumb
(https://github.com/ruby/irb/pull/800)

For apps/libs that test against IRB, it's recommended to set `TERM=dumb`
so they get minimum disruption from Reline's interactive-focus features.

Therefore, we should follow the convention to disable pager when `TERM=dumb`.

8a3002a39e
2023-12-05 16:03:06 +00:00
Stan Lo
52eabf2e32 [ruby/irb] Bump version to v1.10.0
(https://github.com/ruby/irb/pull/798)

4acc9b8d6c
2023-12-03 17:06:41 +00:00
Gary Tou
4ee1f0fb5d [ruby/irb] Implement history command
(https://github.com/ruby/irb/pull/761)

* Implement `history` command

Lists IRB input history with indices. Also aliased as `hist`.

* Add tests for `history` command

* Address feedback: `puts` with multiple arguments instead of `join`ing

* Address feedback: Handle nil from splitting an empty input string

* Refactor line truncation

* Add `-g` grep option to `history` command

* Add `history` command to README

* Remove unused `*args` parameter

* Allow spaces to be included in grep

* Allow `/` to be included in grep regex

* Handle `input` being an empty string

* Exclude "#{index}: " from matching the grep regex

* Add new line after joining

3f9eacbfa9
2023-12-02 04:32:04 +00:00