diff options
author | Yusuke Endoh <[email protected]> | 2021-10-27 11:25:58 +0900 |
---|---|---|
committer | git <[email protected]> | 2021-10-27 11:29:20 +0900 |
commit | 4c32fcb84f19a3821c25f7a01ac995af3826d83e (patch) | |
tree | 164a564543235807c9d291b4150c94d2ef1c2e71 /lib/error_highlight | |
parent | 33844f3096ed15eb1568d6aa333d8040ec9f074a (diff) |
[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
Diffstat (limited to 'lib/error_highlight')
-rw-r--r-- | lib/error_highlight/formatter.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/error_highlight/formatter.rb b/lib/error_highlight/formatter.rb index ce687fb2a2..20ca78d468 100644 --- a/lib/error_highlight/formatter.rb +++ b/lib/error_highlight/formatter.rb @@ -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 |