Regression: Parse methods inside ActiveSupport::Concern included blocks#1753
Regression: Parse methods inside ActiveSupport::Concern included blocks#1753skatkov wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a regression in the Prism-based Ruby parser where method definitions inside ActiveSupport::Concern receiverless included do ... end blocks were no longer visited, causing documented Rails methods (e.g., ActiveRecord::Core.configurations) to be missing from the object store and cross-reference resolution to fail.
Changes:
- Special-case receiverless
includedcalls with a block so the block body is visited directly (without entering the generic “proc/metaprogramming block” mode that ignores method defs). - Add a focused regression test ensuring
def self.configurationsinside anincludedblock is stored and its doc comment is preserved.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/rdoc/parser/ruby.rb | Visits receiverless included block bodies directly so method definitions inside are parsed and recorded. |
| test/rdoc/parser/ruby_test.rb | Adds a regression test asserting methods and comments inside ActiveSupport::Concern included blocks are captured. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| when :included | ||
| node.block ? node.block.body&.accept(self) : super |
| assert_equal ['A::foo', 'A#bar', 'A::configurations', 'A::baz2', 'A#baz3'], methods.map(&:full_name) | ||
| assert_equal ['comment foo', 'comment bar', 'Returns the configuration.'], methods.take(3).map { |m| m.comment.text.strip } |
|
Thanks for the PR, but I don't think we should take this approach. First, on the premise: this behavior didn't come from #819. The pre-Prism parser documented Second, As a workaround, |
Issue
When generating documentation for rails, i'm seeing a following error:
RDoc does not add ActiveRecord::Core.configurations to its object store. Resulting documentation renders label as plain text instead of linking to the method documentation.
Context
Rails defines some documented methods inside concern inclusion blocks:
Previously this block could be parsed, support for ActiveSupport::Concern#included was originally added in #819. During the migration to the Prism parser and subsequent removal of the Ripper parser, this special handling was not carried over.
Solution
Handle special-case receiverless
includedcalls that have a block.Their block body is visited directly, without marking it as a generic proc block. Calls without a block continue through the normal visitor path.
Ordinary metaprogramming blocks remain unchanged and method definitions inside them are still ignored.
Follow-up
@zzak voiced a valid question:
#819 (comment)
This deserves a follow-up PR's.
prependedis analogous and could be a small follow-up usingwhen :included, :prepended.class_methodsneeds separate handling.