diff options
author | Hiroshi SHIBATA <[email protected]> | 2022-12-09 15:12:51 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2022-12-09 16:36:22 +0900 |
commit | 0677bbe3ff139a4f369c128bdab3526450c5ee6f () | |
tree | d114f89cd3150e50cfeaa3d20542287dcacf85ae /lib/syntax_suggest | |
parent | 9557c8edf2dcf18fdece066c596a71696b2f2b30 (diff) |
Merge syntax_suggest master
Pick from https://.com/ruby/syntax_suggest/commit/daee74dcb06296fa69fe8595fdff5d93d432b30d
Notes: Merged: https://.com/ruby/ruby/pull/6890
-rw-r--r-- | lib/syntax_suggest/core_ext.rb | 89 |
1 files changed, 45 insertions, 44 deletions
@@ -3,6 +3,10 @@ # Ruby 3.2+ has a cleaner way to hook into Ruby that doesn't use `require` if SyntaxError.method_defined?(:detailed_message) module SyntaxSuggest class MiniStringIO def initialize(isatty: $stderr.isatty) @string = +"" @@ -16,52 +20,49 @@ if SyntaxError.method_defined?(:detailed_message) attr_reader :string end - end - - SyntaxError.prepend Module.new { - def detailed_message(highlight: true, syntax_suggest: true, **kwargs) - return super unless syntax_suggest - - require "syntax_suggest/api" unless defined?(SyntaxSuggest::DEFAULT_VALUE) - - message = super - - 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 - if file - file = Pathname.new(file) - io = SyntaxSuggest::MiniStringIO.new - - SyntaxSuggest.call( - io: io, - source: file.read, - filename: file, - terminal: highlight - ) - annotation = io.string - - annotation + message - else - message - end - rescue => e - if ENV["SYNTAX_SUGGEST_DEBUG"] - $stderr.warn(e.message) - $stderr.warn(e.backtrace) - end - - # Ignore internal errors - message end - } else autoload :Pathname, "pathname" |