Граф коммитов

211 Коммитов

Автор SHA1 Сообщение Дата
Stan Lo f16c6ac4fd [ruby/irb] Stop using ExtendCommandBundle internally
(https://github.com/ruby/irb/pull/925)

This module was used to extend both commands and helpers when they're not
separated. Now that they are, and we have a Command module, we should move
command-related logic to the Command module and update related references.

This will make the code easier to understand and refactor in the future.

https://github.com/ruby/irb/commit/f74ec97236
2024-04-20 18:55:54 +00:00
tomoya ishida 125e1ed5f7 [ruby/irb] Remove exit command workaround, handle IRB_EXIT in
debug_readline
(https://github.com/ruby/irb/pull/923)

* Remove exit and exti! command workaround when executed outside of IRB

Command was a method. It could be executed outside of IRB.
Workaround for it is no longer needed.

* Handle IRB_EXIT in debug mode

* Add exit and exit! command in rdbg mode

https://github.com/ruby/irb/commit/0b5dd6afd0
2024-04-20 07:45:41 +00:00
tomoya ishida ff599aea7c [ruby/irb] Fix % escape in prompt format
(https://github.com/ruby/irb/pull/927)

https://github.com/ruby/irb/commit/08eee25d28
2024-04-18 14:46:55 +00:00
Lorenzo Zabot 2e978c2cb3 [ruby/irb] Prompt specifiers documentation improvements
(https://github.com/ruby/irb/pull/926)

https://github.com/ruby/irb/commit/e8ea8f253d
2024-04-18 10:33:23 +00:00
Stan Lo 04ba96e619 [ruby/irb] Allow defining custom commands in IRB
(https://github.com/ruby/irb/pull/886)

This is a feature that has been requested for a long time. It is now
possible to define custom commands in IRB.

Example usage:

```ruby
require "irb/command"

class HelloCommand < IRB::Command::Base
  description "Prints hello world"
  category "My commands"
  help_message "It doesn't do more than printing hello world."

  def execute
    puts "Hello world"
  end
end

IRB::Command.register(:hello, HelloCommand)
```

https://github.com/ruby/irb/commit/888643467c
2024-04-14 11:01:43 +00:00
Stan Lo f1d9e895b9 [ruby/irb] Pass statements to Context#evaluate
(https://github.com/ruby/irb/pull/920)

This has a few benefits:

- We can keep hiding the evaluation logic inside the Context level, which
  has always been the convention until #824 was merged recently.
- Although not an official API, gems like `debug` and `mission_control-jobs`
  patch `Context#evaluate` to wrap their own logic around it. This implicit
  contract was broken after #824, and this change restores it.

In addition to the refactor, I also converted some context-level evaluation
tests into integration tests, which are more robust and easier to maintain.

https://github.com/ruby/irb/commit/b32aee4068
2024-04-12 12:01:03 +00:00
Stan Lo 38e3819be6 [ruby/irb] Add a workaround to make IRB work with debug's tests
(https://github.com/ruby/irb/pull/919)

https://github.com/ruby/irb/commit/eb442c4dda
2024-04-10 23:16:32 +00:00
tomoya ishida 6a505d1b59 [ruby/irb] Command implementation not by method
(https://github.com/ruby/irb/pull/824)

* Command is not a method

* Fix command test

* Implement non-method command name completion

* Add test for ExtendCommandBundle.def_extend_command

* Add helper method install test

* Remove spaces in command input parse

* Remove command arg unquote in help command

* Simplify Statement and handle execution in IRB::Irb

* Tweak require, const name

* Always install CommandBundle module to main object

* Remove considering local variable in command or expression check

* Remove unused method, tweak

* Remove outdated comment for help command arg

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

---------

https://github.com/ruby/irb/commit/8fb776e379

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-04-10 16:52:53 +00:00
Joshua Broughton f87e60f1f4 [ruby/irb] Filter backtrace before format in handle_exception
(https://github.com/ruby/irb/pull/916)

handle_exception now applies the filter_backtrace to exception
backtraces prior to formatting the lines with Exception#full_message

This fixes a bug in upstream projects, notably Rails, where the
backtrace filtering logic expects the lines to be formatted as
Exception#backtrace.

https://github.com/ruby/irb/commit/805ee008f9

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2024-04-05 16:25:52 +00:00
Artur d85c24058d [ruby/irb] Remove misleading documentation
(https://github.com/ruby/irb/pull/906)

https://github.com/ruby/irb/issues/904

https://github.com/ruby/irb/commit/89bca01bba
2024-03-22 11:34:51 +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

https://github.com/ruby/irb/commit/e9a175e06b
2024-03-16 13:51:07 +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

https://github.com/ruby/irb/commit/61560b99b3
2024-03-01 15:51:29 +00:00
tomoya ishida f0172fc7ee [ruby/irb] Remove workaround for empty lines in dynamic_prompt
(https://github.com/ruby/irb/pull/884)

https://github.com/ruby/irb/commit/820b9e8dd6
2024-02-23 12:32:59 +00:00
tomoya ishida 598b03648f [ruby/irb] Remove remaining `frozen_string_literal: false` in lib/
(https://github.com/ruby/irb/pull/883)

https://github.com/ruby/irb/commit/4bfdb23ae6
2024-02-23 12:32:50 +00: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

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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`.

https://github.com/ruby/irb/commit/0e9db419be
2024-02-16 16:12:54 +00:00
Yusuke Endoh 25d74b9527 Do not include a backtick in error messages and backtraces
[Feature #16495]
2024-02-15 18:42:31 +09: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

https://github.com/ruby/irb/commit/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!

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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

---------

https://github.com/ruby/irb/commit/c0a5f31679

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-02-10 22:07:53 +00:00
Nuno Silva 1236a74023 [ruby/irb] Skip re-setup when creating a child session
(https://github.com/ruby/irb/pull/850)

https://github.com/ruby/irb/commit/06b2d00dd3
2024-02-01 12:12:06 +00:00
Eddie Lebow fdb8f08639 [ruby/irb] Reword history file documentation and fix typo
(https://github.com/ruby/irb/pull/842)

https://github.com/ruby/irb/commit/bbabf818c7
2024-01-25 10:20:47 +00:00
ydah 819ae2c2c1 [ruby/irb] assigment ==> assignment
https://github.com/ruby/irb/commit/24c7694467
2024-01-25 09:58:16 +00:00
ydah 5f9f46a24c [ruby/irb] reseting ==> resetting
https://github.com/ruby/irb/commit/6209f06c72
2024-01-25 09:58:16 +00:00
ydah 9b1cc68b77 [ruby/irb] configuation ==> configuration
https://github.com/ruby/irb/commit/a27a511777
2024-01-25 09:58:16 +00:00
Eddie Lebow 34315510d3 [ruby/irb] Fix documentation typo, `niL` -> `nil`
https://github.com/ruby/irb/commit/79086a9dda
2024-01-22 04:42:37 +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

https://github.com/ruby/irb/commit/452b543a65
2024-01-06 17:15:16 +00:00
Burdette Lamar 5384e5dfde [ruby/irb] Remove dead doc (https://github.com/ruby/irb/pull/819)
https://github.com/ruby/irb/commit/2d5a1afdf5
2023-12-25 21:12:49 +09:00
Burdette Lamar 4ad1007fd2 [ruby/irb] [DOC] Change indexes.rdoc to indexes.md
(https://github.com/ruby/irb/pull/812)

* Change indexes.rdoc to indexes.md

* Change indexes.rdoc to indexes.md

* Change indexes.rdoc to indexes.md

https://github.com/ruby/irb/commit/b1cd53cbf7
2023-12-20 19:11:02 +09:00
Stan Lo d1cf793adc [ruby/irb] Remove documents about deprecated/WIP features and some
slight adjustments
(https://github.com/ruby/irb/pull/811)

https://github.com/ruby/irb/commit/6a9193e88b
2023-12-12 18:46:07 +00:00
Stan Lo 28a9a4275c [ruby/irb] Remove trailing space
This is required to fix ruby/ruby's CI

https://github.com/ruby/irb/commit/3c77213209
2023-12-12 11:27:39 +00:00
Burdette Lamar 35990cb38c [ruby/irb] [DOC] RDoc for module IRB
(https://github.com/ruby/irb/pull/738)

[DOC] RDoc for module IRB

https://github.com/ruby/irb/commit/f3a0626298
2023-12-12 10:34:38 +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.

https://github.com/ruby/irb/commit/4fedce93d3
2023-11-30 15:22:22 +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.

https://github.com/ruby/irb/commit/412ab26067
2023-11-28 14:05:31 +00:00
tomoya ishida f6b292b5ca [ruby/irb] Fix exception(backtrace=nil) prints nothing
(https://github.com/ruby/irb/pull/782)

https://github.com/ruby/irb/commit/fa9ecf9a5b
2023-11-25 10:16:02 +00:00
tomoya ishida 11d7c75fb3 [ruby/irb] Handle handle_exception's exception
(https://github.com/ruby/irb/pull/780)

https://github.com/ruby/irb/commit/d42138c477
2023-11-23 17:33:13 +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)

https://github.com/ruby/irb/commit/1048c7ed7a
2023-11-08 02:46:33 +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

https://github.com/ruby/irb/commit/cf23be4395
2023-10-21 18:06:00 +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

https://github.com/ruby/irb/commit/1ceb97fe2e
2023-10-12 12:53:31 +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.

https://github.com/ruby/irb/commit/d5b262a076
2023-10-04 12:13:33 +00:00
Chad Schroeder 51e7fb5331 [ruby/irb] fixes https://github.com/ruby/irb/pull/524
(https://github.com/ruby/irb/pull/696)

https://github.com/ruby/irb/commit/59bcc07def
2023-08-29 13:10:35 +00:00
Stan Lo 6ed1a504d4 [ruby/irb] irb:rdbg cleanups (https://github.com/ruby/irb/pull/697)
* Remove unused method and constant from IRB::Debug

* Update comments

https://github.com/ruby/irb/commit/98914a963c
2023-08-29 12:54:25 +00:00
Summer ☀️ 0cd92819c9
[ruby/irb] Remove unused `PROMPT_N`
(https://github.com/ruby/irb/pull/685)

https://github.com/ruby/irb/commit/66e69fa0dc
2023-08-29 18:15:05 +09:00
Stan Lo 86ac17efde [ruby/irb] Move input processing out of RubyLex
(https://github.com/ruby/irb/pull/683)

* Add a test case for Ctrl-C handling

* Test symbol aliases with integration tests

There are a few places that also need to check symbol aliases before
`Irb#eval_input`. But since the current command test skip them, we
don't have test coverage on them.

* Move each_top_level_statement and readmultiline to Irb

This will save RubyLex from knowning information about commands and aliases.

https://github.com/ruby/irb/commit/69cb5b5615
2023-08-21 15:42:15 +00:00
Stan Lo 5a40f7db54 [ruby/irb] Encapsulate input details in Statement objects
(https://github.com/ruby/irb/pull/682)

* Introduce Statement class

* Split Statement class for better clarity

https://github.com/ruby/irb/commit/65e8e68690
2023-08-16 10:13:46 +00:00
Stan Lo 7f8f62c93b [ruby/irb] Support seamless integration with ruby/debug
(https://github.com/ruby/irb/pull/575)

* Support native integration with ruby/debug

* Prevent using multi-irb and activating debugger at the same time

Multi-irb makes a few assumptions:

- IRB will manage all threads that host sub-irb sessions
- All IRB sessions will be run on the threads created by IRB itself

However, when using the debugger these assumptions are broken:

- `debug` will freeze ALL threads when it suspends the session (e.g. when
  hitting a breakpoint, or performing step-debugging).
- Since the irb-debug integration runs IRB as the debugger's interface,
  it will be run on the debugger's thread, which is not managed by IRB.

So we should prevent the 2 features from being used at the same time.
To do that, we check if the other feature is already activated when
executing the commands that would activate the other feature.

https://github.com/ruby/irb/commit/d8fb3246be
2023-08-13 18:30:34 +00:00
Stan Lo 9099d62ac7 [ruby/irb] Move IO configuration to IRB::Irb
(https://github.com/ruby/irb/pull/681)

It shouldn't be `RubyLex`'s responsibility to handle IO. So this moves
the configuration to `IRB::Irb`.

https://github.com/ruby/irb/commit/daff750076
2023-08-13 15:23:04 +00:00
tomoya ishida e1683b4958 [ruby/irb] Drop showing indent level number in DEFAULT prompt and
INF_RUBY prompt
(https://github.com/ruby/irb/pull/679)

* Drop showing indent level number in DEFAULT prompt and INF_RUBY prompt

* Update prompt part of test_rendering's expected result

https://github.com/ruby/irb/commit/3847532e54
2023-08-12 10:19:24 +00:00