ruby / did_you_mean

The gem that has been saving people from typos since 2014
MIT License
1.87k stars 113 forks source link

Formatters cannot be set/got when your implementation does not support Ractors #191

Open enebo opened 11 months ago

enebo commented 11 months ago

I was not passing some MRI pattern matching specs and realized that it was not setting the NullFormatter. It is because formatter requires Ractors to work.

I did a quick fix:

  # Returns the currently set formatter. By default, it is set to +DidYouMean::Formatter+.
  def self.formatter
    storage = defined?(Ractor) ? Ractor : Thread
    storage.current[:__did_you_mean_formatter__] || Formatter
  end

  # Updates the primary formatter used to format the suggestions.
  def self.formatter=(formatter)
    storage = defined?(Ractor) ? Ractor : Thread
    storage.current[:__did_you_mean_formatter__] = formatter
  end

but I suspect this is not right. This is a global setting and not just a thread-specific one...or is it?

yuki24 commented 7 months ago

Apologies for the delay. Did you run into this issue on JRuby or older versions of MRI?

enebo commented 7 months ago

@yuki24 on JRuby. When we try and run C Ruby test suite it disables the did_you_mean formatter. JRuby has no Ractors so it doesn't replace the formatter.