Skip to content
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
merged 1 commit into from
Jun 12, 2024

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Jun 6, 2024

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.

@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Jun 6, 2024
@vinistock vinistock self-assigned this Jun 6, 2024
@vinistock vinistock requested a review from a team as a code owner June 6, 2024 19:44
@vinistock vinistock requested review from andyw8 and st0012 June 6, 2024 19:44
@vinistock vinistock marked this pull request as draft June 6, 2024 19:49
@vinistock vinistock marked this pull request as ready for review June 6, 2024 20:08
@vinistock vinistock force-pushed the vs/create_singleton_klass branch from b443c44 to 54c57d3 Compare June 10, 2024 21:02
@vinistock vinistock requested a review from Morriar June 10, 2024 21:03
@vinistock vinistock force-pushed the vs/create_singleton_klass branch from 54c57d3 to 0ad4129 Compare June 11, 2024 17:20
@st0012 st0012 mentioned this pull request Jun 11, 2024
@vinistock vinistock force-pushed the vs/create_singleton_klass branch from 0ad4129 to 3d79cc4 Compare June 12, 2024 14:19
Copy link
Member

@paracycle paracycle left a 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.

@vinistock vinistock force-pushed the vs/create_singleton_klass branch from 3d79cc4 to 20ab893 Compare June 12, 2024 16:45
@vinistock vinistock force-pushed the vs/create_singleton_klass branch from 20ab893 to 8272b05 Compare June 12, 2024 18:24
@vinistock vinistock enabled auto-merge (squash) June 12, 2024 18:25
@vinistock vinistock merged commit 1daea59 into main Jun 12, 2024
33 checks passed
@vinistock vinistock deleted the vs/create_singleton_klass branch June 12, 2024 18:38
st0012 added a commit that referenced this pull request Jun 12, 2024
PR #2157 relies on Entry::InstanceMethod and Entry::SingletonMethod,
which were merged together in #2142. But because the PRs are merged
side-by-side without rebase, this resulted in a broken build.

This commit reflects the class changes in the RBSIndexer.
@st0012 st0012 mentioned this pull request Jun 12, 2024
st0012 added a commit that referenced this pull request Jun 12, 2024
PR #2157 relies on Entry::InstanceMethod and Entry::SingletonMethod,
which were merged together in #2142. But because the PRs are merged
side-by-side without rebase, this resulted in a broken build.

This commit reflects the class changes in the RBSIndexer.
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.

5 participants