Shopify / ruby-lsp-rails

A Ruby LSP add-on for Rails
https://shopify.github.io/ruby-lsp/rails-add-on
MIT License
581 stars 27 forks source link

Handle `class_methods do` blocks for concerns #525

Closed andyw8 closed 1 week ago

andyw8 commented 2 weeks ago

(details to be added)

cc @toddkummer

andyw8 commented 1 week ago

@toddkummer this shipped in v0.3.27, if you want to check it's working wth your gem.

toddkummer commented 1 week ago

The current version of the gem has an extra level of indirection: the main controller mixin includes two modules that each have the class_methods do block.

For example, the gem might be implemented by mixing the module into the ApplicationController:

class ApplicationController < ActionController::Base
  include Filterameter::DeclarativeFilters
  ...

Which then uses one more level of includes...

module Filterameter
  module DeclarativeFilters
    extend ActiveSupport::Concern
    include Filterameter::Filterable
    include Filterameter::Sortable
    ...

To finally get to the class_methods do block...

module Filterameter
  module Filterable
    extend ActiveSupport::Concern
    class_methods do
      ...
      def filter(name, options = {})
      ...

The extra level of indirection seems to prevent the hover and Go To Definition from working. When I collapse it so that the first include has the class_methods do block, it does work. Here is a commit that shows that change.

I was leaning towards making that change anyways, so this fix does resolve my issue. I just wanted to share the additional finding with you in case it is valuable.


I think this confirms I am testing all this on the latest version:

$ less .ruby-lsp/Gemfile.lock | grep ruby-lsp-rails
    ruby-lsp-rails (0.3.27)