diff --git a/CHANGELOG.md b/CHANGELOG.md index f806903..884a1c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## HEAD (unreleased) +- Native support of `SyntaxError#path`, support 3.2.0-preview3 will be dropped with the release of 3.2.0-preview4 () - Added dependabot for GitHub Actions (https://github.com/ruby/syntax_suggest/pull/160) ## 1.0.1 diff --git a/lib/syntax_suggest/core_ext.rb b/lib/syntax_suggest/core_ext.rb index 40f5fe1..59e13a1 100644 --- a/lib/syntax_suggest/core_ext.rb +++ b/lib/syntax_suggest/core_ext.rb @@ -25,15 +25,21 @@ def detailed_message(highlight: true, syntax_suggest: true, **kwargs) require "syntax_suggest/api" unless defined?(SyntaxSuggest::DEFAULT_VALUE) message = super - file = if highlight + + file = if respond_to?(:path) + path + elsif highlight + # This branch will be removed when the next Ruby 3.2 preview is released with + # support for SyntaxError#path SyntaxSuggest::PathnameFromMessage.new(super(highlight: false, **kwargs)).call.name else SyntaxSuggest::PathnameFromMessage.new(message).call.name end - io = SyntaxSuggest::MiniStringIO.new - if file + file = Pathname.new(file) + io = SyntaxSuggest::MiniStringIO.new + SyntaxSuggest.call( io: io, source: file.read,