Shopify / Shopify/ruby-lsp-rails

Handle active support concern's recursive nature

Open
#547 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Ruby
Stars
688
Forks
44
PR merge metrics
No merged PRs in 30d

Description

This might require some infrastructure changes and new APIs in the Ruby LSP side, but we came to realize that there's one aspect of concerns we are unable to match with the current approach.

If a concern includes another concern which defines class methods, those class methods are recursively extended to all other including concerns. For example:

module ConcernWithClassMethods
  extend ActiveSupport::Concern

  module ClassMethods
    def foo; end
  end
end

module OtherConcern
  extend ActiveSupport::Concern
  include ConcernWithClassMethods
end

OtherConcern.foo # ok!

module YetAnotherConcern
  extend ActiveSupport::Concern
  include OtherConcern
end

YetAnotherConcern.foo # ok!

class Bar
  include YetAnotherConcern
end

Bar.foo # ok!

This is a bit challenging to fix with our current architecture because ancestor linearization is done all lazily for better performance and in this particular example, ancestors of the attached class alter the ancestors of the singleton class.

That is, you need to linearize the ancestors of Bar to discover that Bar::<Class:Bar> inherits from ConcernWithClassMethods::ClassMethods. We may need some way to have concerns mark the namespaces that include them with some flag telling the algorithm that, for those namespaces, you have to first linearize the attached class in order to accurately linearize the singleton class.

Contributor guide

Open the contributing guide

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 reproducing the nested ActiveSupport::Concern example in the issue and tracing the lazy ancestor linearization for Bar and its singleton class. Inspect the concern handling and ancestor-linearization entry points; done means recursively included concerns expose their class methods on the final class without losing the current performance approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.