-
Notifications
You must be signed in to change notification settings - Fork 178
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
Associate singleton methods with the right owner objects #2142
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
st0012
approved these changes
Jun 6, 2024
Morriar
reviewed
Jun 6, 2024
Morriar
reviewed
Jun 6, 2024
b443c44
to
54c57d3
Compare
54c57d3
to
0ad4129
Compare
0ad4129
to
3d79cc4
Compare
st0012
reviewed
Jun 12, 2024
paracycle
approved these changes
Jun 12, 2024
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.
The changes look good to me, but let's make sure to test that given:
class Foo
class << self
def self.foo
end
end
end
the owner of the foo
method is <Class:<Class:Foo>>
.
Nothing else seems to be exercising the when Prism::SelfNode
case inside a singleton class.
amomchilov
approved these changes
Jun 12, 2024
3d79cc4
to
20ab893
Compare
20ab893
to
8272b05
Compare
st0012
added a commit
that referenced
this pull request
Jun 12, 2024
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
First step for #1939
This PR starts indexing singleton contexts and associating entities to singleton owners.
Next up is fixing the ancestor of singleton classes, which take a few more things into account than what we're currently doing.
Implementation
The idea is to maintain the same approach we've been using for constants so far because everything else works by default if we do it (constant, ivar and method resolutions and lookups).
We essentially use a special name to declare the singleton namespace, which matches somewhat what Ruby does
<Class:Name>
. It works exactly like any other namespace.This makes it easy to resolve and lookup things. We can simply build the exact same nesting structure on the language server and then pass those namespaces for resolution.
Automated Tests
I added tests demonstrating that resolution for methods, constants and ivars already work by default by following this approach.