Commit graph

934 commits

Author SHA1 Message Date
Hiroshi SHIBATA
8cfa8e87b2 [ruby/irb] Fix a typo (https://github.com/ruby/irb/pull/912)
2057248e40
2024-03-26 11:30:33 +00:00
tomoya ishida
f53209f023 [ruby/irb] Cache RDoc::RI::Driver.new
(https://github.com/ruby/irb/pull/911)

* Cache RDoc::RI::Driver.new to improve performance and to avoid flaky test

* Insert sleep to fix flaky rendering test that renders document dialog

da84e6cb56
2024-03-25 11:48:11 +00:00
OKURA Masafumi
e6487a9263 [ruby/irb] docs(help): Add latest options to ja help message
(https://github.com/ruby/irb/pull/903)

3c6d452495
2024-03-18 02:37:42 +00:00
tomoya ishida
bda5b09937 [ruby/irb] Fix irb_history saved to current directory
(https://github.com/ruby/irb/pull/901)

* Always save irb_history in HOME or XDG_CONFIG_HOME

Also split irbrc search logic from irb_history search logic as a refactor

* Remove IRB.conf[:RC_NAME_GENERATOR] because it's not configurable

This conf is used to specify which irbrc to load. Need to configure before irbrc is loaded, so it's actually not configurable.
This conf is also used for history file search, but it is configurable by conf[:HISTORY_FILE].

* remove rc_file_test because it is tested with rc_files, remove useless test setup

* Make internal irbrc searching method private

11d03a6ff7
2024-03-16 15:20:03 +00:00
Stan Lo
137b52a881 [ruby/irb] Use markdown format for docs
(https://github.com/ruby/irb/pull/890)

* Convert irb.rb's document into markdown format

* Hide should-be-private top-level methods from docs

* Skip xmp.rb's docs

* Declare lib/irb.rb's markup do it works in ruby/ruby too

* Ignore docs folder

e9a175e06b
2024-03-16 13:51:07 +00:00
Go
d10afe0357 [ruby/irb] Rescue from exceptions raised by #name
(https://github.com/ruby/irb/pull/899)

* Rescue from exceptions raised by #name

Irb might terminate if the class overwrites `name` and raise errors. This commit rescue irb from termination.

* fix for other unknown patterns

35b87cf893
2024-03-14 15:41:03 +00:00
hogelog
3822ca9884 [ruby/irb] Add disable_irb command to disable debug of binding.irb
(https://github.com/ruby/irb/pull/898)

* Add disable_irb command to disable debug of binding.irb

* disable_irb doesn't override Kernel.exit

Kernel.exit call is removed because disable_irb does not override Kernel.exit
and workaround to https://bugs.ruby-lang.org/issues/18234 is not needed.

29901e4f21
2024-03-14 15:40:27 +00:00
alpaca-tc
e8f796e954 [ruby/irb] rdoc version lock is required
(https://github.com/ruby/irb/pull/897)

Some features of irb do not work properly when using the old rdoc.
I have compared several major versions and found that it works as intended from 4.0.0.

This problem occurs when there is a Gemfile.lock is installed with the old rdoc.
I don't know why this Gemfile.lock installs an older rdoc than the ruby bundled rdoc,
but specifying the version in the gemspec will at least prevent the problem.

NOTE: ruby/irb#704 problem does not occur with this change.

The following is test code.

```
 ### Usage: ruby __FILE__.rb
 # # input RDoc and Tab
 # >> RDoc<Tab>
 #
 ### Expect: Display document of RDoc
 ### Actual: <internal:marshal>:34:in `load': instance of RDoc::Constant needs to have method `marshal_load' (TypeError)
require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
  gem 'irb'
  # gem 'rdoc', '~> 4.0.0'
  gem 'rdoc', '~> 3.12.0'
end

require 'rdoc'
require 'irb'

IRB.start
```

1a1fbba020
2024-03-08 09:23:40 +00:00
Stan Lo
9fcb2bd5c0 [ruby/irb] Bump version to v1.12.0
(https://github.com/ruby/irb/pull/895)

a79e84a692
2024-03-07 02:14:44 +00:00
Haroon Ahmed
8f6113a91e [ruby/irb] Add the ability to fetch and load multiple irb files.
(https://github.com/ruby/irb/pull/859)

This allows hierarchy when loading rc files for example both files below
are loaded;

project/.irbrc
~/.irbrc

b53ebc6655

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-03-05 16:07:45 +00:00
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