[前][次][番号順一覧][スレッド一覧]

ruby-changes:69469

From: Yusuke <ko1@a...>
Date: Wed, 27 Oct 2021 11:29:34 +0900 (JST)
Subject: [ruby-changes:69469] 4c32fcb84f (master): [ruby/error_highlight] Make the formatter mechanism support Ractor

https://git.ruby-lang.org/ruby.git/commit/?id=4c32fcb84f

From 4c32fcb84f19a3821c25f7a01ac995af3826d83e Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Wed, 27 Oct 2021 11:25:58 +0900
Subject: [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
---
 lib/error_highlight/formatter.rb             | 8 +++-----
 test/error_highlight/test_error_highlight.rb | 4 ++--
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/error_highlight/formatter.rb b/lib/error_highlight/formatter.rb
index ce687fb2a28..20ca78d468a 100644
--- a/lib/error_highlight/formatter.rb
+++ b/lib/error_highlight/formatter.rb
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/lib/error_highlight/formatter.rb#L1
 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 https://github.com/ruby/ruby/blob/trunk/lib/error_highlight/formatter.rb#L14
   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
diff --git a/test/error_highlight/test_error_highlight.rb b/test/error_highlight/test_error_highlight.rb
index 9fc14202b5f..08036bca542 100644
--- a/test/error_highlight/test_error_highlight.rb
+++ b/test/error_highlight/test_error_highlight.rb
@@ -5,7 +5,7 @@ require "tempfile" https://github.com/ruby/ruby/blob/trunk/test/error_highlight/test_error_highlight.rb#L5
 
 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 https://github.com/ruby/ruby/blob/trunk/test/error_highlight/test_error_highlight.rb#L13
   def setup
     if defined?(DidYouMean)
       @did_you_mean_old_formatter = DidYouMean.formatter
-      DidYouMean.formatter = DummyFormatter.new
+      DidYouMean.formatter = DummyFormatter
     end
   end
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]