Skip to content

Conversation

tommycrumrine
Copy link

@tommycrumrine tommycrumrine commented Aug 7, 2025

Motivation

Shows references for methods defined with attr_reader, attr_writer, attr_accessor

Re-opening stale PR #2848. Sorry this fell off my radar!

Closes #2668

Implementation

attr_reader, attr_writer, attr_accessor are just methods, so on call node if we detect one of these methods, and one of the arguments match the target method name, add the reference.

Additionally, I have ensured it works with empty and string arguments as well as added tests for these cases.

Automated Tests

Yes!

Manual Tests

Screenshot 2024-11-15 at 1 43 07 PM

Copy link

graphite-app bot commented Aug 7, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@tommycrumrine tommycrumrine marked this pull request as ready for review August 7, 2025 01:48
@tommycrumrine tommycrumrine requested a review from a team as a code owner August 7, 2025 01:48
@tommycrumrine tommycrumrine changed the title Add attr method references Adds support for attr_* method references Aug 7, 2025
Copy link
Contributor

@egiurleo egiurleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for re-opening your PR and apologies for the slow response on our end! I just left two quick questions. I'll also re-run CI for you to make sure the tests look good.

if @target.is_a?(MethodTarget) && (name = node.name.to_s) == @target.method_name
@references << Reference.new(
name,
node.message_loc, #: as !nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does type checking pass without this #: as !nil?

def unescaped_argument_names(node)
return [] if node.arguments.nil?

node.arguments.arguments.select { |arg| arg.respond_to?(:unescaped) }.map(&:unescaped)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can node.arguments.arguments be nil?

@egiurleo egiurleo added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support attr_* for References
2 participants