(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
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
(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
(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
(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>
(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>
(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
(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
(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
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
(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
(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
(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>
(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
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
(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
(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
(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
(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