(https://github.com/ruby/irb/pull/498)
When the main object is frozen, `IRB` wraps a `SimpleDelegator` around it.
But because `SimpleDelegator` doesn't delegate private methods, methods like
`require_relative` or `const_get` would cause error, which are needed for
lazily loading commands.
This commit works around this limitation by avoiding those private method calls
when setting up command execution.
methods
(https://github.com/ruby/irb/pull/502)
* Remove unnecessary parameter defaults
These methods are always called with tokens specified. So their default
`@tokens` value is never used and is misleading.
* Remove unnecessary context default
* Require tokens for `RubyLex#check_state`
(https://github.com/ruby/irb/pull/504)
* Simplify `RubyLex#set_prompt`
It's optional argument is never used by any caller.
* Remove the optional `p` argument from `RubyLex#set_input`
The argument is only used in a test case, which can be easily replaced by
a block argument.
(https://github.com/ruby/irb/pull/489)
* Remove unnecessary Binding#source_location check
`Binding#source_location` was added in 2.6, which is the minimum supported
version now. So this check is no longer necessary.
* Remove unused IRB.delete_caller
This method was added in the earliest version of IRB:
f47808999d
But it's not currently referenced by anything. We can verify this with a
org-wide search result:
https://github.com/search?q=org%3Aruby+delete_caller&type=code
(https://github.com/ruby/irb/pull/350)
Simplify part of regex ``[_a-zA-Z0-9]`` with equivalent shorthand ``\w``.
Replace case-when with match ``$1`` or default value ``?"``, making intention more clear.
(https://github.com/ruby/irb/pull/478)
Given that `show_doc` already supports syntax like `String#gsub`, it
should be able to take it in non-string form too, like `edit` and
`show_source` do. This ensures users can have a consistent syntax on
argument between different commands.
The current `next` pre-command workaround on IRB source stepping
moves the location by 1 extra line. A better way is to make `debug`
skip IRB frames completely, which is what this commit does.
It also fixes the step command's test. The `|` in regexp was not escaped
so it was always incorrectly matched.
(https://github.com/ruby/irb/pull/475)
In the long-term, we want to align with `Pry`, `byebug` and `debug` to
use the `help` command to list all commands, which is what `show_cmds`
currently does. And `show_doc` will be the command to look up Ruby APIs.
By aliasing `show_doc` to the current `help` now, users will have time
to get use to it.
(https://github.com/ruby/irb/pull/473)
* Handle file loading commands' argument error gracefully
Currently, if users don't provide an argument to `source`,
`irb_load`, and `irb_require`, IRB raises `ArgumentError` with full
stacktrace. This is confusing because it looks similar to when IRB has
internal issues. The message also isn't helpful on helping users avoid
the error.
So in this commit, I add a new `CommandArgumentError` for commands to
raise explicitly when users' input doesn't satisfy a command's argument
requirement.
* Gracefully handle `fg` command's argument requirement
(https://github.com/ruby/irb/pull/472)
* Lazily load the multi-irb extension
We now have plan to implement a command that prints all commands'
information, which will need to load all command files without actually
running them.
But because the `multi-irb` extension patches IRB's top-level methods,
loading it would cause unintentional side-effects.
So this commit moves related requires into command execution to avoid the problem.
* Make extend_irb_context private
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
`IRB_USE_AUTOCOMPLETE=false`
(https://github.com/ruby/irb/pull/469)
* Allow using IRB_USE_AUTOCOMPLETE=false to disable autocompletion
Currently, the only 2 ways to disable autocompletion are:
1. Create `.irbrc` and set `IRB.conf[:USE_AUTOCOMPLETE] = false`
2. Add the `--noautocomplete` flag when using the `irb` executable
Both of them are less convenient than setting a env var and are
lesser known to devs.
And given the number of problems the autocompletion has (see #445), I
think we should allow disabling it with a simple `IRB_USE_AUTOCOMPLETE=false`.
* Mention some env var configs in the README
(https://github.com/ruby/irb/pull/449)
* Seamlessly integrate a few debug commands
* Improve the break command support
* Utilize skip_src option if available
* Add step and delete commands
* Write end-to-end tests for each debugger command
* Add documentation
* Add backtrace, info, catch commands
https://github.com/ruby/irb/commit/976100c1c2
(https://github.com/ruby/irb/pull/448)
* Minor fixes on debug command
* Discover and load debug.gem even if it's not in Gemfile
* Eliminate else for rescue
* Discover the latest one from all gem paths
Based on this commit: 93f87ec653
It appears that the maintainer @aycabta wanted to deprecate any `USE_*LINE` configs in favor of
`USE_MULTILINE`. So we should deprecate `USE_RELINE` as well.
https://github.com/ruby/irb/commit/478f19f3ae
(https://github.com/ruby/irb/pull/437)
* Transform ls's --grep/-G option to keyword args
* Make --grep less flexible
* Support -g instead of --grep
* Suppress warnings from symbol aliases
There are a few downsides of the current approach:
1. Because gem specs are lazily retrieved, this computation happens in
every irb completion test case, which is not necessary. (In tests we
don't cache the result of `retrieve_files_to_require_from_load_path`)
2. Gem::Specification.latest_specs is sensible to the content of
LOAD_PATH. And when combined with 1, tests fail "randomly" if they
try to mutate LOAD_PATH, even though the test subject it's something
else.
So by pre-computing and storing the gem paths in a constant, it guarantees
that the computation only happens once and it doesn't get affected by test
cases.
One argument could be made against the change is that, it'll store
unnecessary data for users that disable autocompletion. But the
counter-arguments are:
1. Since autocompletion is enabled by default, this should not be the
case for most users.
2. For users with autocompletion enabled, IRB already caches the
result of `retrieve_files_to_require_from_load_path` in memory, which
should have a similar size of GEM_SPECS. And we currently haven't
received any report about problems caused by such memory consumption.
https://github.com/ruby/irb/commit/c671d39020
(https://github.com/ruby/irb/pull/427)
* Make sure `RubyLex#set_input`'s context is always present in tests
In real-world scenarios, the context should always be non-nil:
https://github.com/ruby/irb/blob/master/lib/irb.rb#L489
So we should make sure our test setup reflects that.
* Make context a required keyword
Since in practice, `set_input`'s context should always be non-nil, its
parameters should reflect that.
And since `RubyLex#check_state` is only called by `#lex` and
`#set_input`, both of which now always require context, we can assume
its context should be non-nil too.
https://github.com/ruby/irb/commit/1aeeb86203
https://no-color.org has been updated (jcs/no_color#83):
> Command-line software which adds ANSI color to its output by default
should check for a `NO_COLOR` environment variable that, when present
and **not an empty string** (regardless of its value), prevents the
addition of ANSI color.
https://github.com/ruby/irb/commit/46e0f7e370
Co-authored-by: Stan Lo <stan001212@gmail.com>
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.
https://github.com/ruby/irb/commit/b1278b7320
Removing /\A.+\n/ could have an unexpected impact, depending on how
RubyLex.generate_local_variables_assign_code is implemented. It feels
like a too much assumption and the intention isn't immediately clear,
so I added these changes.
https://github.com/ruby/irb/commit/ccc07a35ce