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 methods invoked on self #1195

Merged
merged 7 commits into from
Nov 22, 2023
Merged

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Nov 20, 2023

Motivation

Big step towards #899

I got frustrated that we keep getting feedback about missing method support and powered through some basic implementations.

This PR adds support for

  • Workspace symbols (for all methods)
  • Definition, completion and hover for methods invoked directly on self (since the receiver is known)

We are not taking inheritance into account yet, this is just a first step. The same ideas from this PR can be applied to singleton methods once #1113 is merged.

Then we'll just be missing inheritance and methods with unknown receivers.

Implementation

I recommend reviewing per commit. For the most part, all implementations just use resolve_method or check method owners when necessary.

The only exception is workspace symbol. We were just not supporting the method kind, which completely implements the functionality.

Automated Tests

Added tests for all of these.

@vinistock vinistock added the enhancement New feature or request label Nov 20, 2023
@vinistock vinistock self-assigned this Nov 20, 2023
@vinistock vinistock requested a review from a team as a code owner November 20, 2023 16:28
lib/ruby_lsp/requests/hover.rb Outdated Show resolved Hide resolved
@@ -82,7 +85,7 @@ def markdown_from_index_entries(title, entries)
markdown_title = "```ruby\n#{title}\n```"
definitions = []
content = +""
entries.each do |entry|
Array(entries).each do |entry|
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. This wasn't caught by Sorbet before?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, it might be a mistake I made splitting the commits. I think I included the signature change for this method in the wrong commit, separate from the code changes. Sorbet did identify that Array required Kernel.

test/requests/hover_expectations_test.rb Show resolved Hide resolved
lib/ruby_lsp/requests/hover.rb Show resolved Hide resolved
test/requests/workspace_symbol_test.rb Show resolved Hide resolved
lib/ruby_lsp/requests/definition.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/definition.rb Show resolved Hide resolved
Base automatically changed from vs/add_resolve_method to main November 20, 2023 20:30
@vinistock vinistock force-pushed the vs/support_methods_invoked_on_self branch from d425972 to 1b640a2 Compare November 20, 2023 20:57
@vinistock vinistock force-pushed the vs/support_methods_invoked_on_self branch from 1b640a2 to 63823e7 Compare November 21, 2023 19:43
@vinistock vinistock force-pushed the vs/support_methods_invoked_on_self branch from 63823e7 to d45ab4a Compare November 21, 2023 19:44
@vinistock vinistock requested a review from Morriar November 21, 2023 19:45
@vinistock vinistock merged commit 6202347 into main Nov 22, 2023
@vinistock vinistock deleted the vs/support_methods_invoked_on_self branch November 22, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants