Skip to content

Commit

Permalink
Extract common behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Aug 8, 2024
1 parent 307d039 commit 12bbd46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
18 changes: 18 additions & 0 deletions lib/ruby_indexer/lib/ruby_indexer/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,19 @@ def decorated_parameters

"(#{first_signature.format})"
end

sig { returns(String) }
def formatted_signatures
overloads_count = signatures.size
case overloads_count
when 1
""
when 2
"\n(+1 overload)"
else
"\n(+#{overloads_count - 1} overloads)"
end
end
end

class Accessor < Member
Expand Down Expand Up @@ -543,6 +556,11 @@ def decorated_parameters
@target.decorated_parameters
end

sig { returns(String) }
def formatted_signatures
@target.formatted_signatures
end

sig { returns(T::Array[Signature]) }
def signatures
@target.signatures
Expand Down
7 changes: 1 addition & 6 deletions lib/ruby_lsp/listeners/hover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,7 @@ def handle_method_hover(message, inherited_only: false)
first_method = T.must(methods.first)

title = "#{message}#{first_method.decorated_parameters}"
overloads_count = first_method.signatures.size
if overloads_count == 2
title << "\n(+1 overload)"
elsif overloads_count > 2
title << "\n(+#{overloads_count - 1} overloads)"
end
title << first_method.formatted_signatures

if type.is_a?(TypeInferrer::GuessedType)
title << "\n\nGuessed receiver: #{type.name}"
Expand Down
8 changes: 1 addition & 7 deletions lib/ruby_lsp/requests/completion_resolve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ def perform

if first_entry.is_a?(RubyIndexer::Entry::Member)
label = +"#{label}#{first_entry.decorated_parameters}"

overloads_count = first_entry.signatures.size
if overloads_count == 2
label << "\n(+1 overload)"
elsif overloads_count > 2
label << "\n(+#{overloads_count - 1} overloads)"
end
label << first_entry.formatted_signatures
end

guessed_type = @item.dig(:data, :guessed_type)
Expand Down

0 comments on commit 12bbd46

Please sign in to comment.