Commit graph

507 commits

Author SHA1 Message Date
tomoya ishida
a2197466a2 [ruby/irb] Disable pager in eval_history test
(https://github.com/ruby/irb/pull/799)

ee85e84935
2023-12-03 14:05:16 +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
Kasumi Hanazuki
5fc71feb6c [ruby/irb] Rescue errors from main.to_s/inspect when formatting
prompt
(https://github.com/ruby/irb/pull/791)

Currently, IRB just terminates if `main.to_s` raises while IRB
constructs the prompt string. This can easily happen if the user wants
to start an IRB session in the instance scope of an uninitialized
object, for example:

```
class C
  def initialize
    binding.irb
    @values = []
  end

  def to_s = @values.join(',')  # raises if uninitialized
end

C.new
```

This patch makes IRB rescue from such an exception and displays the
class name of the exception instead of `main.to_s` to indicate some
error has occurred.

We may display more detailed information about the exception, but this
patch chooses not to do so because 1) the prompt has limited space,
2) users can evaluate `to_s` in IRB to examine the error if they want,
and 3) obtaining the details can also raise, which requires nested
exception handling and can be complicated.

412ab26067
2023-11-28 14:05:31 +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
tomoya ishida
f6b292b5ca [ruby/irb] Fix exception(backtrace=nil) prints nothing
(https://github.com/ruby/irb/pull/782)

fa9ecf9a5b
2023-11-25 10:16:02 +00:00
hogelog
68a03613d8 [ruby/irb] Fix flaky test case
test_autocomplete_with_multiple_doc_namespaces
(https://github.com/ruby/irb/pull/786)

85c6ddeb7d
2023-11-25 10:14:07 +00:00
tomoya ishida
11d7c75fb3 [ruby/irb] Handle handle_exception's exception
(https://github.com/ruby/irb/pull/780)

d42138c477
2023-11-23 17:33:13 +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
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
Hiroshi SHIBATA
536649f819
Fix IRB tests (#8925)
* Revert "Fixup da2c2931a6"

This reverts commit e1978a905a.

* Revert "Skip Type completion tests related with IRB::VERSION"

This reverts commit da2c2931a6.

* require irb/version to test IRB::VERSION

---------

Co-authored-by: tompng <tomoyapenguin@gmail.com>
2023-11-15 14:58:51 +09:00
Hiroshi SHIBATA
e1978a905a Fixup da2c2931a6 2023-11-15 12:11:12 +09:00
Hiroshi SHIBATA
da2c2931a6 Skip Type completion tests related with IRB::VERSION 2023-11-15 11:02:16 +09:00
Hiroshi SHIBATA
197ab823ba
Revert "Tests of irb is still broken."
This reverts commit 5398bbcbab.

  We explicitly load rubygems at rubygems_ext.rb

  8840d8507b
2023-11-15 10:09:00 +09:00
Hiroshi SHIBATA
5398bbcbab
Tests of irb is still broken.
Revert "[ruby/irb] Revert "Skip TypeCompletion test in ruby ci"

  This reverts commit 589e2b6782.
2023-11-10 08:29:55 +09:00
Hiroshi SHIBATA
589e2b6782 [ruby/irb] Revert "Skip TypeCompletion test in ruby ci
(https://github.com/ruby/irb/pull/748)"
(https://github.com/ruby/irb/pull/755)

This reverts commit d394af0bbc.

a9d0145115
2023-11-10 07:56:07 +09: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
8da33bff8c [ruby/irb] Skip TypeCompletion test in ruby ci
(https://github.com/ruby/irb/pull/748)

d394af0bbc
2023-11-08 06:42:10 +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
Stan Lo
85beca6e41 [ruby/irb] Use IRB's own doc for doc dialog tests
(https://github.com/ruby/irb/pull/743)

* Use IRB's own doc for doc dialog tests

* Run doc dialog tests for older Rubies too

* Remove unnecessary CI setups

97a2b86f0a
2023-10-30 18:22:02 +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
Nobuyoshi Nakada
06a4011964 [ruby/irb] Suppress "Switch to inspect mode" messages
This message is displayed if STDIN is not a tty.  The parallel test is
the case.

e26e90e3fb
2023-10-16 12:09:05 +00:00
tomoya ishida
75fb3cf458 [ruby/irb] Restore encoding in InputCompletor test
(https://github.com/ruby/irb/pull/732)

ef77c232cf
2023-10-14 15:02:38 +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
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
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
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
tomoya ishida
c9e28ea2f9 [ruby/irb] Fix Reline's test failure running with `make test-all
TESTS='reline irb'`
(https://github.com/ruby/irb/pull/722)

* Specify TestInputMethod in test to avoid RelineInputMethod to be used

* Reset Reline in teardown to avoid test failure of `make test-all TESTS="irb reline"`

5d67967eb1
2023-09-30 17:56:06 +00:00
tomoya ishida
c2c0a083f0 [ruby/irb] Disable pager in show-source test
(https://github.com/ruby/irb/pull/720)

5669efa4c1
2023-09-26 10:06:17 +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
tomoya ishida
8b4e54f979 [ruby/irb] Test should not depend on user's irbrc file specified by
ENV['IRBRC']
(https://github.com/ruby/irb/pull/717)

1d2d35dd33
2023-09-17 21:25:49 +00:00
tomoya ishida
cd67c0d204 [ruby/irb] Test should not depend on user's irbrc file
(https://github.com/ruby/irb/pull/714)

02703c46f9
2023-09-16 22:27:04 +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
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
tomoya ishida
062eec7558 [ruby/irb] Add --nomultiline indent and prompt test
(https://github.com/ruby/irb/pull/699)

9b4aea753b
2023-08-29 15:34:49 +00:00
Stan Lo
0cfb779692 [ruby/irb] Fix test warnings (https://github.com/ruby/irb/pull/698)
* Encoding should be saved before creating Irb objects

* Fix unused local warning

036ec31034
2023-08-29 12:48:33 +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
Peter Zhu
a97dedf761 [ruby/irb] Fix deprecation test when ran multiple times
(https://github.com/ruby/irb/pull/695)

ae0e5bb80f
2023-08-26 13:56:51 +00: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