Skip to content

Commit

Permalink
Handle method aliases in completion resolve (#2590)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Sep 20, 2024
1 parent 43631c2 commit 8d1009e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ruby_lsp/requests/completion_resolve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def perform

if owner_name
entries = entries.select do |entry|
(entry.is_a?(RubyIndexer::Entry::Member) || entry.is_a?(RubyIndexer::Entry::InstanceVariable)) &&
entry.owner&.name == owner_name
(entry.is_a?(RubyIndexer::Entry::Member) || entry.is_a?(RubyIndexer::Entry::InstanceVariable) ||
entry.is_a?(RubyIndexer::Entry::MethodAlias)) && entry.owner&.name == owner_name
end
end

Expand Down
22 changes: 22 additions & 0 deletions test/requests/completion_resolve_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,28 @@ def test_indicates_signature_count_in_label_details
end
end

def test_resolve_handles_method_aliases
with_server("", stub_no_typechecker: true) do |server, _uri|
index = server.instance_variable_get(:@global_state).index
RubyIndexer::RBSIndexer.new(index).index_ruby_core

# This is initially an unresolved method alias. In regular operations, completion runs first, resolves the alias
# and then completionResolve doesn't have to do it. For the test, we need to do it manually
index.resolve_method("kind_of?", "Kernel")

existing_item = {
label: "kind_of?",
kind: RubyLsp::Constant::CompletionItemKind::METHOD,
data: { owner_name: "Kernel" },
}

server.process_message(id: 1, method: "completionItem/resolve", params: existing_item)

result = server.pop_response.response
assert_match("**Definitions**: [kernel.rbs]", result[:documentation].value)
end
end

def test_completion_documentation_for_guessed_types
source = +<<~RUBY
class User
Expand Down

0 comments on commit 8d1009e

Please sign in to comment.