mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
Just leaves `SyntaxSuggest.handle_error` and `SyntaxSuggest::VERSION` visible. Removes some public/private annotations since ony public stuff is now documented. https://github.com/ruby/syntax_suggest/commit/18c62ce100
46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module SyntaxSuggest
|
|
# Used to monkeypatch SyntaxError via Module.prepend
|
|
def self.module_for_detailed_message # :nodoc:
|
|
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
|
|
|
|
if path
|
|
file = Pathname.new(path)
|
|
io = SyntaxSuggest::MiniStringIO.new
|
|
|
|
SyntaxSuggest.call(
|
|
io: io,
|
|
source: file.read,
|
|
filename: file,
|
|
terminal: highlight
|
|
)
|
|
annotation = io.string
|
|
|
|
annotation += "\n" unless annotation.end_with?("\n")
|
|
|
|
annotation + message
|
|
else
|
|
message
|
|
end
|
|
rescue => e
|
|
if ENV["SYNTAX_SUGGEST_DEBUG"]
|
|
warn(e.message)
|
|
warn(e.backtrace)
|
|
end
|
|
|
|
# Ignore internal errors
|
|
message
|
|
end
|
|
}
|
|
end
|
|
end
|
|
|
|
SyntaxError.prepend(SyntaxSuggest.module_for_detailed_message)
|