Skip to content

find instance variable references with matched scopes #3377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

monkeyWzr
Copy link
Contributor

Motivation

#2787 (review)

Implementation

Find instance variables references only with matched scopes.

Automated Tests

Added.

Manual Tests

Right click on an instance variable and select Find All References.

@monkeyWzr monkeyWzr requested a review from a team as a code owner April 4, 2025 19:33
Copy link

graphite-app bot commented Apr 4, 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.

@monkeyWzr monkeyWzr changed the title find instance variable references with matched scope find instance variable references with matched scopes Apr 4, 2025
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

This is great! I have some minor comments, but looks good to ship

super()
@name = name
@receiver_ancestors = receiver_ancestors
Copy link
Member

Choose a reason for hiding this comment

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

Let's call this owner_ancestors since instance variables don't technically have a receiver.

@@ -321,7 +325,10 @@ def collect_constant_references(name, location)
def collect_instance_variable_references(name, location, declaration)
return unless @target.is_a?(InstanceVariableTarget) && name == @target.name

@references << Reference.new(name, location, declaration: declaration)
receiver_type = @stack.join("::")
Copy link
Member

Choose a reason for hiding this comment

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

This helper method handles the namespaces considering top level references too.

module Foo
  class ::Bar; end
end
Suggested change
receiver_type = @stack.join("::")
receiver_type = Index.actual_nesting(@stack, nil)

Comment on lines +369 to +370
def find_instance_variable_references(instance_variable_name, receiver_ancestors, source)
target = ReferenceFinder::InstanceVariableTarget.new(instance_variable_name, receiver_ancestors)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def find_instance_variable_references(instance_variable_name, receiver_ancestors, source)
target = ReferenceFinder::InstanceVariableTarget.new(instance_variable_name, receiver_ancestors)
def find_instance_variable_references(instance_variable_name, owner_ancestors, source)
target = ReferenceFinder::InstanceVariableTarget.new(instance_variable_name, owner_ancestors)

@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels May 15, 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.

2 participants