-
Notifications
You must be signed in to change notification settings - Fork 195
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
base: main
Are you sure you want to change the base?
find instance variable references with matched scopes #3377
Conversation
How to use the Graphite Merge QueueAdd 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. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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("::") |
There was a problem hiding this comment.
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
receiver_type = @stack.join("::") | |
receiver_type = Index.actual_nesting(@stack, nil) |
def find_instance_variable_references(instance_variable_name, receiver_ancestors, source) | ||
target = ReferenceFinder::InstanceVariableTarget.new(instance_variable_name, receiver_ancestors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
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
.