From 551f64745fa0ba0ea70812f63495f2fa7dd5afe4 Mon Sep 17 00:00:00 2001 From: Noah Gibbs Date: Wed, 21 Feb 2024 21:11:07 +0000 Subject: [ruby/prism] Allow skipping warnings as needed, and pass a reason through to Parser::Diagnostic https://github.com/ruby/prism/commit/6a84a3c9fb --- lib/prism/translation/parser.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3