Commit graph

899 commits

Author SHA1 Message Date
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
hogelog
ef466ac931 [ruby/irb] Scrub past history input before split
(https://github.com/ruby/irb/pull/795)

* Scrub past history input before split

* Don't rewrite ENV["LANG"]

0f344f66d9
2023-12-01 18:04:03 +00:00
Stan Lo
f193f96d31 [ruby/irb] Page evaluation result's output
(https://github.com/ruby/irb/pull/784)

* Page evaluation result's output

This will make it easier to work with long output that exceeds the terminal's height.

* Use consistent TERM in rendering tests

This makes sure we get consistent result on all platforms.

4fedce93d3
2023-11-30 15:22:22 +00:00
tomoya ishida
86d9a6dcb6 [ruby/irb] Use gem repl_type_completor, remove type_completion
implementation
(https://github.com/ruby/irb/pull/772)

a4868a5373
2023-11-29 16:30:13 +00:00
Peter Zhu
fadd28c7ba [ruby/irb] Change show_source tests into integration tests
* Remove trailing spaces

* Migrate show_source tests to integration tests

Because show_source tests often need to define class and/or methods,
they can easily leak state to other tests. Changing them to integration
tests will ensure that they are run in a clean environment.

* Fix NoMethodError caused by SourceFinder#method_target

3c39f13397
2023-11-28 12:22:46 -05:00
paulreece
891ce4614a [ruby/irb] This enhancement allows a user to add the -s flag if they
want to access a methods origin definition.  It allows for chaining
of multiple esses to further go up the classes as needed.
(https://github.com/ruby/irb/pull/770)

eec1329d5a
2023-11-28 14:56:51 +00:00
Stan Lo
a07d84b63c [ruby/irb] Hide debugger hint after the input is submitted
(https://github.com/ruby/irb/pull/789)

If `output_modifier_proc`'s `complete` arg is true, it means the input is
submitted. In that case, debugger hint doesn't provide value to users
and adds noise to the output. So we hide it in such case.

f86d9dbe2f
2023-11-27 10:34:40 +00:00
Stan Lo
cc5d1bf026 [ruby/irb] Display aliases in help message
(https://github.com/ruby/irb/pull/788)

Similar to Pry, it displays user-defined aliases in the help message with
a dedicated section. With the current default aliases, it looks like:

```
...other sections...

Aliases
  $              Alias for `show_source`
  @              Alias for `whereami`
```

2a0eacc891
2023-11-26 17:07:45 +00:00
Stan Lo
9cd086ba4b [ruby/irb] Support disabling pager
(https://github.com/ruby/irb/pull/783)

With either `IRB.conf[:USE_PAGER] = false` or `--no-pager` commnad line flag.

I decided use `--no-pager` instead of `--use-pager` because it matches with
Pry and git's command line flags.

df1c3b9042
2023-11-26 11:07:50 +00:00
Stan Lo
e8b9058964 [ruby/irb] Hint debugger command in irb:rdbg session
(https://github.com/ruby/irb/pull/768)

When user enters irb:rdbg session, they don't get the same hint that the
`debug` gem provides, like

```
(rdbg) n    # next command
```

This means that users may accidentally execute commands when they want to
retrieve the value of a variable.

So this commit adds a Reline output modifier to add a simiar hint:

```
irb:rdbg(main):002> n # debug command
```

It is not exactly the same as `debug`'s because in this case the importance
is to help users distinguish between value evaluation and debugger command
execution.

fdf24de851
2023-11-23 07:29:12 +00:00
hogelog
e2078ccd5a [ruby/irb] Fix failure of more command with -R option
(https://github.com/ruby/irb/pull/781)

7d6849e44e
2023-11-23 07:24:35 +00:00
tomoya ishida
8d6175bf64 [ruby/irb] Require prism >= 0.18.0 (MatchWriteNode#targets and
CaseMatchNode)
(https://github.com/ruby/irb/pull/778)

943c14b12e
2023-11-22 20:29:51 +00:00
tomoya ishida
ea60bf912c [ruby/irb] Rescue Exception, ignore warning in completion
doc_namespace
(https://github.com/ruby/irb/pull/777)

c2f671611a
2023-11-22 12:06:25 +00:00
tomoya ishida
f954a5663a [ruby/irb] Bump version to 1.9.1
(https://github.com/ruby/irb/pull/773)

997df3e849
2023-11-21 13:02:21 +00:00
ima1zumi
7164715666 [ruby/irb] Enable Setting Completer Type through IRB_COMPLETOR
(https://github.com/ruby/irb/pull/771)

I propose introducing the capability to set the IRB completion kinds via an environment variable, specifically `IRB_COMPLETOR=type`.
This feature aims to enhance the Rails console experience by allowing Rails users to specify their preferred completion more conveniently.

Currently, when using the Rails console, there's no straightforward way to globally set the type completion across a Rails application repository.
It's possible to configure this setting by placing a `.irbrc` file at the project root. However, using a .irbrc file is not ideal as it allows for broad configurations and can potentially affect the production environment.
My suggestion focuses on allowing users to set the completion to 'type' in a minimal.

This enhancement would be particularly beneficial for teams writing RBS in their Rails applications.
This type completer, integrated with RBS, would enhance completion accuracy, improving the Rails console experience.

032f6da25f
2023-11-21 00:04:41 +00:00
tomoya ishida
631b500dd5 [ruby/irb] Fix irb crash on {}. completion
(https://github.com/ruby/irb/pull/764)

07e4d540cc
2023-11-18 17:49:06 +00:00
ima1zumi
8044feb7ab [ruby/irb] Bump version to 1.9.0
(https://github.com/ruby/irb/pull/757)

41548b8bd0
2023-11-10 19:27:30 +00:00
tomoya ishida
c4efd17061 [ruby/irb] Add command line option to select which completor to use
(https://github.com/ruby/irb/pull/754)

* Add command line option to select which completor to use

* Add test for completor argv

1dec2708c9
2023-11-09 13:15:26 +00:00
tomoya ishida
e344010465 [ruby/irb] Type based completion using Prism and RBS
(https://github.com/ruby/irb/pull/708)

* Add completor using prism and rbs

* Add TypeCompletion test

* Switchable completors: RegexpCompletor and TypeCompletion::Completor

* Add completion info to irb_info

* Complete reserved words

* Fix [*] (*) {**} and prism's change of KeywordParameterNode

* Fix require, frozen_string_literal

* Drop prism<=0.16.0 support

* Add Completor.last_completion_error for debug report

* Retrieve `self` and `Module.nesting` in more safe way

* Support BasicObject

* Handle lvar and ivar get exception correctly

* Skip ivar reference test of non-self object in ruby < 3.2

* BaseScope to RootScope, move method objects constant under Methods

* Remove unused Splat struct

* Drop deeply nested array/hash type calculation from actual object. Now, calculation depth is 1

* Refactor loading rbs in test, change preload_in_thread not to cache Thread object

* Use new option added in prism 0.17.1 to parse code with localvars

* Add Prism version check and warn when :type completor cannot be enabled

* build_type_completor should skip truffleruby (because endless method definition is not supported)

1048c7ed7a
2023-11-08 02:46:33 +00:00
tomoya ishida
c8d4b103a9 [ruby/irb] Fix dancing-ruby Ctrl+C stop
(https://github.com/ruby/irb/pull/735)

802b1cb6d8
2023-11-08 09:17:23 +09:00
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