diff options
| author | Noah Gibbs <the.codefolio.guy@gmail.com> | 2024-02-21 21:11:07 +0000 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-02-21 22:38:48 +0000 |
| commit | 551f64745fa0ba0ea70812f63495f2fa7dd5afe4 (patch) | |
| tree | 14ce0df9e068dcd9bc9a924acae63ab161109d22 | |
| parent | 45ae69e37e1dac60ea8f6d682ff7b947cb8057d0 (diff) | |
[ruby/prism] Allow skipping warnings as needed, and pass a reason through to Parser::Diagnostic
https://github.com/ruby/prism/commit/6a84a3c9fb
| -rw-r--r-- | lib/prism/translation/parser.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/prism/translation/parser.rb b/lib/prism/translation/parser.rb index c9e4f148ce..10f4a70dc1 100644 --- a/lib/prism/translation/parser.rb +++ b/lib/prism/translation/parser.rb @@ -17,9 +17,9 @@ module Prism attr_reader :message # Initialize a new diagnostic with the given message and location. - def initialize(message, level, location) + def initialize(message, level, reason, location) @message = message - super(level, :prism_error, {}, location, []) + super(level, reason, {}, location, []) end end @@ -106,6 +106,12 @@ module Prism true end + # This is a hook to allow consumers to disable some warnings if they don't + # want them to block creating the syntax tree. + def valid_warning?(warning) + true + end + # If there was a error generated during the parse, then raise an # appropriate syntax error. Otherwise return the result. def unwrap(result, offset_cache) @@ -113,13 +119,13 @@ module Prism next unless valid_error?(error) location = build_range(error.location, offset_cache) - diagnostics.process(Diagnostic.new(error.message, :error, location)) + diagnostics.process(Diagnostic.new(error.message, :error, :prism_error, location)) end result.warnings.each do |warning| next unless valid_warning?(warning) location = build_range(warning.location, offset_cache) - diagnostics.process(Diagnostic.new(warning.message, :warning, location)) + diagnostics.process(Diagnostic.new(warning.message, :warning, :prism_warning, location)) end result |
