Skip to content

Commit

Permalink
Trigger signature help for typespecs
Browse files Browse the repository at this point in the history
Fixes #957
  • Loading branch information
lukaszsamson committed Jul 27, 2023
1 parent a9a55be commit 8645d64
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions apps/language_server/lib/language_server/providers/completion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do

# add trigger signatures to arity 0 if there are higher arity completions that would trigger
commands = items
|> Enum.filter(& &1.kind in [:function])
|> Enum.filter(& &1.kind in [:function, :class])
|> Enum.group_by(&{&1.kind, &1.label})
|> Map.new(fn {key, values} ->
command = Enum.find_value(values, & &1.command)
Expand All @@ -175,8 +175,8 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do

items = items
|> Enum.map(fn
%{command: nil} = item ->
command = commands[{item.kind, item.label}]
%{command: nil, kind: kind} = item when kind in [:function, :class] ->
command = commands[{kind, item.label}]
if command do
%{item |
command: command,
Expand Down Expand Up @@ -630,7 +630,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
defp from_completion_item(
%{type: :type_spec, metadata: metadata} = suggestion,
_context,
_options
options
) do
%{
name: name,
Expand All @@ -656,6 +656,19 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
"#{name}()"
end

signature_help_supported? = Keyword.get(options, :signature_help_supported, false)
signature_after_complete? = Keyword.get(options, :signature_after_complete, true)

trigger_signature? = signature_help_supported? && arity > 1

command =
if trigger_signature? && signature_after_complete? do
%{
"title" => "Trigger Parameter Hint",
"command" => "editor.action.triggerParameterHints"
}
end

%__MODULE__{
label: name,
detail: "typespec #{signature}",
Expand All @@ -667,7 +680,8 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
insert_text: snippet,
priority: 10,
kind: :class,
tags: metadata_to_tags(metadata)
tags: metadata_to_tags(metadata),
command: command
}
end

Expand Down

0 comments on commit 8645d64

Please sign in to comment.