ruby / ruby/did_you_mean

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

Open
#191 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.9k
Forks
113
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the formatter getter and setter shown in the issue, including how they use Ractor or Thread storage. Determine whether formatter state should be global or thread-specific, then verify that setting and reading the formatter works on implementations without Ractors and that the relevant pattern-matching specs pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.