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

Support Hover, Completion, Go to definition for Class Variables #2944

Conversation

rogancodes
Copy link
Contributor

@rogancodes rogancodes commented Dec 1, 2024

Motivation

closes #2897

Implementation

I’ve made separate commits for each feature, hoping it makes the review process easier.

Automated Tests

Added new tests

Manual Tests

Screencast.from.01-12-24.07.46.01.PM.IST.webm

@rogancodes rogancodes requested a review from a team as a code owner December 1, 2024 14:53
@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Dec 11, 2024
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 looking great. Just a small gotcha about class variables that we need to be careful about

lib/ruby_indexer/lib/ruby_indexer/index.rb Outdated Show resolved Hide resolved
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 very close. Just a couple of other things and we can finally ship. I appreciate the effort on this addition!

Completion resolve

The definitions documentation is missing.

image

This is happening because we're missing the new entry type in this check.

Completion trigger

I also noticed that we don't get any completion suggestions until entering the second @ symbol. This happens because, until you add the second one, you have an instance variable node, rather than a class variable node.

I think it would be nice to show class variables as part of the completion when you add a single @ symbol, since there's a chance that the user is looking for those.

That said, I just wanted to document this for a future PR. Please don't worry about it in this one.

lib/ruby_lsp/type_inferrer.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/listeners/definition.rb Outdated Show resolved Hide resolved
@rogancodes
Copy link
Contributor Author

Good catch on completion resolve. I completely forgot to check the definition during completion.

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.

Great work on this. Thanks for sticking with it and pushing an entire full set of features over the finish line 🚀

Regarding the completion when inserting a single @, it seems that it's a bit more nuanced. It works as expected inside instance methods, but whenever we're inside any level of singleton contexts then we only get completion after the second @ is inserted.

Screen.Recording.2025-01-03.at.10.20.36.AM.mov

I also checked and inheritance doesn't seem to be playing a role in it, so it's likely there's some tiny difference in how singleton contexts are being handled. I think writing a completion test for this specific example and then debugging will reveal where the issue is.

I'll ship the PR to avoid delaying it any further. Let me know if you want to take a stab at the completion thing, otherwise I can create an issue for it

@vinistock vinistock merged commit 316d4b0 into Shopify:main Jan 3, 2025
24 checks passed
@rogancodes
Copy link
Contributor Author

Sure, I'll work on it.

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.

Add definition, hover and completion support for class variables
3 participants