Commit graph

109 commits

Author SHA1 Message Date
Hiroshi SHIBATA
077558ee2b
[Bug #20511] Update reline-0.5.7 (#10848)
* Update reline-0.5.7

* Update irb-1.13.1
2024-05-28 15:54:39 -07: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
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
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
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
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
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
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
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
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
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
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
tomoya ishida
d5ef373b11 [ruby/irb] Set maximum document dialog height by
preferred_dialog_height provided by Reline
(https://github.com/ruby/irb/pull/591)

df6907aca9
2023-05-28 09:20:18 +00:00
Adam Daniels
b54b388f2a [ruby/irb] Display mod key as Option on Darwin platforms
(https://github.com/ruby/irb/pull/584)

Check RUBY_PLATFORM for `darwin` and modify the mod key from `Alt` to
`Option`.
2023-05-19 01:33:32 +00:00
Stan Lo
e9930b51b2 [ruby/irb] Retire magic-file.rb
(https://github.com/ruby/irb/pull/574)

`MagicFile` was introduced around v0.9.6, which was like 14~15 years ago.
It was needed because back then we needed to read a file's magic comment
to determine the encoding of it, and read it with that encoding.

Commit: 3ee79e89

But now we expect files to be encoded in UTF-8 and don't specify encoding
through magic comments anymore, `MagicFile` can be retired.
2023-04-28 17:20:20 +00:00
Hiroshi SHIBATA
7e283c585e [ruby/irb] Formatting to header styles
cef125850d
2023-01-11 22:29:10 +00:00
Hiroshi SHIBATA
c7bb8d67b7 [ruby/irb] Removed Release Version and Revisions for old VCS software
07fae94862
2023-01-11 22:29:09 +00:00
st0012
4f348e482c [ruby/irb] Rename leftover Reidline references
0ed8b103ed
2022-11-15 10:08:28 +00:00
st0012
b7622d792d [ruby/irb] Move require out of repeated execution path
SHOW_DOC_DIALOG will be called repeatedly whenever the corresponding key
is pressed, but we only need to require rdoc once. So ideally the
require can be put outside of the proc.

And because when rdoc is not available the entire proc will be
nonfunctional, we can stop registering the SHOW_DOC_DIALOG if we failed
to require rdoc.

b1278b7320
2022-10-24 13:36:57 +00:00
tomoya ishida
a09f764ce5 [ruby/irb] Always use local variables in current context to parse code (https://github.com/ruby/irb/pull/397)
* Use local_variables for colorize, code_block_open check, nesting_level and assignment_expression check

* Check if expression is an assignment BEFORE evaluating it. evaluate might define new localvars and change result of assignment_expression?

* Add local_variables dependent code test

* pend local variable dependent test on truffleruby

code_block_open is not working on truffleruby

* Always pass context to RubyLex#lex

* Rename local_variable_assign_code generator method name

* Add assignment expression truncate test

* Add Context#local_variables and make generate_local_variables_assign_code more simple

* Update lib/irb/input-method.rb

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Add a comment why assignment expression check should be done before evaluate

c8b3877281

Co-authored-by: Stan Lo <stan001212@gmail.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-10-18 05:44:07 +00:00
Gannon McGibbon
19e4a4c624 [ruby/irb] Rename IDB::ReidlineInputMethod to IRB::RelineInputMethod
Deprecates IDB::ReidlineInputMethod and USE_REIDLINE in favor of
IRB::RelineInputMethod and USE_RELINE. The Input method uses Reline to
read input from the console, so it can be named directly after the
Reline library like other inputs methods are (Readline, Stdio, etc.).

5bcade7130
2022-10-05 17:14:19 +09:00
Jeremy Evans
b07db96744 [ruby/irb] Support --noscript option to not use first non-option argument as script
Also add --script option to turn the option back on.

Previously there wasn't a way to get an interactive IRB session
and access arguments provided on the command line.

Additionally, handle `-` as script as stdin. In Unix-like tools, `-`
means to take standard input instead of a file.  This doesn't
result in exactly the same output for:

```
echo 'p ARGV' > args.rb; irb args.rb a b c
```

and

```
echo 'p ARGV' | irb - a b c
```

Due to how irb handles whether stdin is a tty.

However, this change allows use of `-` as a argument, instead of
giving an unrecognized switch error. This required some small
changes to context.rb (to handle `-` as standard input) and
input-method.rb (to have FileInputMethod accept IO arguments in
addition to strings).

Implements [Feature #15371]

4192683ba2
2022-09-17 02:25:26 +09:00
Jun Aruga
3504be1bc1 [ruby/irb] Require RDoc in input-method.rb again in a limited scope.
RDoc is implemented as soft dependency in IRB. See how the rdoc is required in
the files. I reverted the commit below.

```
$ grep -ril rdoc lib/
lib/irb/cmd/help.rb
lib/irb/completion.rb
lib/irb/easter-egg.rb
lib/irb/input-method.rb
```

---

Revert "Remove `require` in signal handler to avoid ThreadError"

This reverts commit 5f749c613c.

b24852058f
2022-08-26 09:57:02 +09:00
Vít Ondruch
46c3a93982 [ruby/irb] Drop hard dependency on RDoc.
This has been introduced in 026700499d,
but it seems that this is just be mistake, otherwise the later handling
of `LoadError` would not be needed.

54c8df06ff
2022-08-23 18:01:35 +09:00
Peter Jones
e0bfdb23af [ruby/irb] Ensure stdout is a TTY before calling winsize
When outputting a (possibly truncated) value, IRB will query the
window size.  However, if IRB was piped to another process, stdout
will no longer be a TTY and will not support the `winsize` method.

This fix ensure that stdout is a TTY.

125de5eeea
2022-06-26 14:40:48 +09:00
Samuel Williams
e4cd319f3d [ruby/irb] Prefer IO#wait_readable over IO#select. (https://github.com/ruby/irb/pull/323)
1c03bd3373
2021-12-29 09:37:05 +09:00
aycabta
ddf0cdee4f [ruby/irb] Support showing doc by dialog in iTerm2
a4b95d6634
2021-12-25 12:56:40 +09:00
ima1zumi
d486286f1d [ruby/irb] Add Alt+d keycode when convert-meta isn't used
I pushed reline#389 for when convert-meta is not turned on in .inputrc.
Alt+D in irb also needs to be set to the keycode for not using convert-meta.

328eddf851
2021-12-03 00:51:41 +09:00
aycabta
866a09dd9e [ruby/irb] Add --extra-doc-dir option to show doc dialog
3f79cb506f
2021-10-11 21:12:57 +09:00
aycabta
1507cb084c [ruby/irb] Determine left and right when the width of either side is zero correctly
5df6e1f027
2021-10-08 10:34:06 +09:00
aycabta
576eccf76d [ruby/irb] Calculate right side doc dialog width correctly
f34da7fa04
2021-10-08 10:33:56 +09:00
aycabta
374efa8e30 [ruby/irb] Specify whether to show the doc dialog on the left or right side by using variable names
a23a88b8c9
2021-10-08 10:33:47 +09:00
aycabta
5c02df8296 [ruby/irb] Display doc dialog in gaps on narrow screen
4d7cefcaa4
2021-10-08 10:33:39 +09:00
Kaíque Kandy Koga
80e2242da6 [ruby/irb] Update descriptions of methods
From Reidline to Reline

Update description used in take_corresponding_syntax_to_kw_do and is_the_in_correspond_to_a_for methods

Use possessive noun correctly

Second element

4fa9714d6f
2021-10-07 23:55:54 +09:00
Masataka Pocke Kuwabara
853ca5cceb [ruby/irb] Remove require in signal handler to avoid ThreadError
`rdoc` has been required so it looks unnecessary

5f749c613c
2021-10-03 21:51:54 +09:00
aycabta
2a4bacce8c [ruby/irb] Add comments for Alt+d key sequences
4cb5f7e546
2021-09-06 06:39:02 +09:00
aycabta
991eb4894d [ruby/irb] Use multiple trap_key
416abe2524
2021-09-06 05:24:41 +09:00
aycabta
5f771f4f02 [ruby/irb] Remove commeted out code
7dda1f803e
2021-09-04 21:59:39 +09:00
aycabta
c8bf45f23c [ruby/irb] Show doc at the same height as the autocompletion dialog
a9db71e6bc
2021-09-04 21:57:11 +09:00
aycabta
f7d9dd2e4c [ruby/irb] Render properly if both autocomplete and show doc dialogs are left of the cursor
0090203107
2021-09-04 21:55:55 +09:00
aycabta
3d6a475587 [ruby/irb] Use Reline::Key for trap_key in dialog callback
b05ce3c72d
2021-09-03 04:28:53 +09:00
aycabta
eb92d7c732 [ruby/irb] Add message to show full doc
6370a5d974
2021-09-03 04:28:32 +09:00
aycabta
f793f68264 [ruby/irb] Add Alt+d trap from show doc dialog to show full doc
368327b082
2021-09-03 04:28:27 +09:00
aycabta
817694481c [ruby/irb] Set the dialog width to render with a fixed width
80c4329643
2021-08-31 15:20:34 +09:00
aycabta
077bc98ce4 [ruby/irb] Follow that Dialog#contents_width has been renamed to #width
49a73d929e
2021-08-31 15:20:27 +09:00
aycabta
a8e6a850d5 [ruby/irb] Make show doc dialog appears on the left at the right edge
6480eddd31
2021-08-31 15:20:22 +09:00
aycabta
cf0ece810a [ruby/irb] Rename a variable "dialog" with "autocomplete_dialog"
Because it's just used to receive data from the autocomplete dialog, not
for show doc dialog.

f8b752bd98
2021-08-31 15:20:17 +09:00
aycabta
c63d98b401 [ruby/irb] Use DialogRenderInfo
5bc3a72ca3
2021-08-31 05:24:55 +09:00