Adds the `syntax_suggest` syntax error display tool to Ruby through the same mechanism as `error_highlight` and `did_you_mean`. Reference ticket: https://bugs.ruby-lang.org/issues/18159close#4845
## What is syntax_suggest?
When a syntax error is raised by requiring a file, dead_end will use a combination of indentation and lexing to identify the problem.
> Note: Previously this tool was named `dead_end`.
## Known issues
- SyntaxSearch's approach of showing syntax errors only works through integration with `require`, `load`, `autoload`, and `require_relative` (since it monkeypatches them to detect syntax errors). It does not work with direct Ruby file invocations https://github.com/zombocom/dead_end/issues/31.
- This causes failure in the test suite (test_expected_backtrace_location_when_inheriting_from_basic_object_and_including_kernel) and confusion when inspecting backtraces if there's a different error when trying to require a file such as measuring memory (https://github.com/zombocom/syntax_suggest/issues/124#issuecomment-1006705016).
- Discussed fix. We previously talked about opening up `SyntaxError` to be monkeypatched in the same way that other gems hook into `NoMethodError`. This is currently not possible and requires development work. When we last talked about it at RubyKaigi Nobu expressed an ability to make such a change.
Although 'RubyGems' are always available in upstream Ruby, it might not
be available optionally when Ruby is delivered via packaging systems.
E.g. Linux distributions.
Although 'did_you_mean' is always available in upstream Ruby, it might
not be available when speed, memory, disk or network bandwidth is a
concern. This is typically the case for production environment, where
'did_you_mean' is of limited usage.
Also it might not be available optionally when Ruby is delivered via
packaging systems. E.g. Linux distributions.
Activating the gem puts the gem on the load path, where simply requiring
the file will search every gem that's installed until it can find a gem
that contains the `did_you_mean` file.
Calling RubyGems' `require` will search each installed gem until it can
find one that contains the file it should require. This means that the
more gems you have installed, the longer it can take to require that
gem.
To see this in action, lets compare the number of `stat` calls for a
"bare require" vs the number of `stat` calls for a require that follows
a gem activation by using these two programs:
```
[aaron@TC rubygems (master)]$ cat req_dym.rb
begin
require 'did_you_mean'
rescue LoadError
end
[aaron@TC rubygems (master)]$ cat gem_dym.rb
begin
gem 'did_you_mean'
require 'did_you_mean'
rescue Gem::LoadError, LoadError
end
```
The first program just requires the `did_you_mean` gem, where the second
one activates the gem, then requires it. We can count the number of
`stat` calls using `dtrace`:
```
[aaron@TC rubygems (master)]$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
[aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean req_dym.rb" | wc -l
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
283
[aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean gem_dym.rb" | wc -l
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
13
```
The "bare require" version does over 10x the number of stat calls
compared to the "gem, then require" version. Of course the number for
the first one depends on the number of gems you have installed that sort
before the `did_you_mean` gem.
Lets also look at trunk Ruby:
```
[aaron@TC rubygems (master)]$ ruby -v
ruby 2.4.0dev (2016-02-25 trunk 53940) [x86_64-darwin15]
[aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean req_dym.rb" | wc -l
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
2325
[aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean gem_dym.rb" | wc -l
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
685
```
This change will reduce the number of `stat` calls on trunk Ruby too,
but since this installation doesn't have the `did_you_mean` gem,
RubyGems is still reading every gem spec file so that it can raise a
`Gem::LoadError` exception with a nice error message. If we can modify
RubyGems a little, it may be possible to drop the number of stat calls
even on a Ruby installation that doesn't have the `did_you_mean` gem.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
option `--disable_did_you_mean`.
* gem_prelude.rb: now requires did_you_mean gem by default if available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This solves the gem loading issue by never touching $LOAD_PATH
in gem_prelude and instead loading all of rubygems more quickly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
gem activation does not work by default. Now it can be worked
around by requiring "rubygems" first. [ruby-core:29486]
a patch from Evan Phoenix in [ruby-core:31096].
* lib/rubygems.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
It caused many failures on test-all and following is SEGV.
./ruby -e 'require %!#{"foo/" * 10000}foo!'
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
get rid of creating same regexps many times.
* lib/rubygems/custom_require.rb (Kernel#require): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
and must force_encoding before gsub.
cf. Yen Sign problem of SJIS [ruby-core:26910]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
so that ruby finds gems in ~/.gem/.
(Gem.user_home): reduced version of lib/rubygems.rb's.
Gem.default_path needs it.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
so that copy & paste for lib/rubygems/default.rb is not necessary.
* gem_prelude.rb: removes copied codes from lib/rubygems/defaults.rb.
uses require instead.
* common.mk (prelude.c): adds dependency for lib/rubygems/defaults.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
an alternative in $: so that Kernel.#require does not load
more rubygems.rb.
Resolves many failures in test/rubygems/*.
* gem_prelude.rb (Gem.load_full_rubygems_library): supports case
the rubygems to load is not in $(rubylibprefix).
(Gem.path_to_full_rubygems_library): new method for the changes in
purelib.rb and Gem.load_full_rubygems_library.
(Gem.fake_rubygems_as_loaded): new method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
check for requirement if the gem is installed. a patch from
Kyosuke MOROHASHI at [ruby-dev:38020].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Generalizing rb_default_{external,internal}_encoding seems to be
difficult.
default_external cannot be NULL even before detected. [ruby-dev:37390]
* encoding.c (rb_default_external_encoding): has its own
implementation again.
* encoding.c (rb_default_internal_encoding): ditto.
* gem_prelude.rb: added notice.
* ruby.c (rubylib_mangled_path, rubylib_mangled_path2): uses locale
encoding but not ASCII-8BIT.
* ruby.c (process_options): refers less to default_external.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
messages. interpolation does not occur inside single quotes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e