зеркало из https://github.com/github/ruby.git
[ruby/error_highlight] Make the formatter mechanism support Ractor
Now the formatter configuration is per Ractor. DefaultFormatter is used if not set. DefaultFormatter#message_for is now a class method to allow sub-Ractors to call the method. https://github.com/ruby/error_highlight/commit/9fbaa8ab7c
This commit is contained in:
Родитель
33844f3096
Коммит
4c32fcb84f
|
@ -1,6 +1,6 @@
|
|||
module ErrorHighlight
|
||||
class DefaultFormatter
|
||||
def message_for(spot)
|
||||
def self.message_for(spot)
|
||||
# currently only a one-line code snippet is supported
|
||||
if spot[:first_lineno] == spot[:last_lineno]
|
||||
indent = spot[:snippet][0...spot[:first_column]].gsub(/[^\t]/, " ")
|
||||
|
@ -14,12 +14,10 @@ module ErrorHighlight
|
|||
end
|
||||
|
||||
def self.formatter
|
||||
@@formatter
|
||||
Ractor.current[:__error_highlight_formatter__] || DefaultFormatter
|
||||
end
|
||||
|
||||
def self.formatter=(formatter)
|
||||
@@formatter = formatter
|
||||
Ractor.current[:__error_highlight_formatter__] = formatter
|
||||
end
|
||||
|
||||
self.formatter = DefaultFormatter.new
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ require "tempfile"
|
|||
|
||||
class ErrorHighlightTest < Test::Unit::TestCase
|
||||
class DummyFormatter
|
||||
def message_for(corrections)
|
||||
def self.message_for(corrections)
|
||||
""
|
||||
end
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ class ErrorHighlightTest < Test::Unit::TestCase
|
|||
def setup
|
||||
if defined?(DidYouMean)
|
||||
@did_you_mean_old_formatter = DidYouMean.formatter
|
||||
DidYouMean.formatter = DummyFormatter.new
|
||||
DidYouMean.formatter = DummyFormatter
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче