1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Setup SyntaxSuggest as default gem

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/18159

close #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.
This commit is contained in:
schneems 2022-07-26 15:16:21 -05:00 committed by Hiroshi SHIBATA
parent 3541f32951
commit a50df1ab0e
Notes: git 2022-08-19 10:02:48 +09:00
3 changed files with 14 additions and 0 deletions

View file

@ -17,3 +17,10 @@ begin
rescue LoadError rescue LoadError
warn "`did_you_mean' was not loaded." warn "`did_you_mean' was not loaded."
end if defined?(DidYouMean) end if defined?(DidYouMean)
begin
require 'syntax_suggest/core_ext'
rescue LoadError
warn "`syntax_suggest' was not loaded."
end if defined?(SyntaxSuggest)

6
ruby.c
View file

@ -94,6 +94,8 @@ void rb_warning_category_update(unsigned int mask, unsigned int bits);
SEP \ SEP \
X(did_you_mean) \ X(did_you_mean) \
SEP \ SEP \
X(syntax_suggest) \
SEP \
X(rubyopt) \ X(rubyopt) \
SEP \ SEP \
X(frozen_string_literal) \ X(frozen_string_literal) \
@ -307,6 +309,7 @@ usage(const char *name, int help, int highlight, int columns)
M("gems", "", "rubygems (only for debugging, default: "DEFAULT_RUBYGEMS_ENABLED")"), M("gems", "", "rubygems (only for debugging, default: "DEFAULT_RUBYGEMS_ENABLED")"),
M("error_highlight", "", "error_highlight (default: "DEFAULT_RUBYGEMS_ENABLED")"), M("error_highlight", "", "error_highlight (default: "DEFAULT_RUBYGEMS_ENABLED")"),
M("did_you_mean", "", "did_you_mean (default: "DEFAULT_RUBYGEMS_ENABLED")"), M("did_you_mean", "", "did_you_mean (default: "DEFAULT_RUBYGEMS_ENABLED")"),
M("syntax_suggest", "", "syntax_suggest (default: "DEFAULT_RUBYGEMS_ENABLED")"),
M("rubyopt", "", "RUBYOPT environment variable (default: enabled)"), M("rubyopt", "", "RUBYOPT environment variable (default: enabled)"),
M("frozen-string-literal", "", "freeze all string literals (default: disabled)"), M("frozen-string-literal", "", "freeze all string literals (default: disabled)"),
#if USE_MJIT #if USE_MJIT
@ -1553,6 +1556,9 @@ ruby_opt_init(ruby_cmdline_options_t *opt)
if (opt->features.set & FEATURE_BIT(did_you_mean)) { if (opt->features.set & FEATURE_BIT(did_you_mean)) {
rb_define_module("DidYouMean"); rb_define_module("DidYouMean");
} }
if (opt->features.set & FEATURE_BIT(syntax_suggest)) {
rb_define_module("SyntaxSuggest");
}
} }
rb_warning_category_update(opt->warn.mask, opt->warn.set); rb_warning_category_update(opt->warn.mask, opt->warn.set);

View file

@ -73,6 +73,7 @@ REPOSITORIES = {
pathname: "ruby/pathname", pathname: "ruby/pathname",
digest: "ruby/digest", digest: "ruby/digest",
error_highlight: "ruby/error_highlight", error_highlight: "ruby/error_highlight",
syntax_suggest: "zombocom/syntax_suggest",
un: "ruby/un", un: "ruby/un",
win32ole: "ruby/win32ole", win32ole: "ruby/win32ole",
} }