Skip to content

Commit 8645d64

Browse files
committed
Trigger signature help for typespecs
Fixes #957
1 parent a9a55be commit 8645d64

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

apps/language_server/lib/language_server/providers/completion.ex

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
166166

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

176176
items = items
177177
|> Enum.map(fn
178-
%{command: nil} = item ->
179-
command = commands[{item.kind, item.label}]
178+
%{command: nil, kind: kind} = item when kind in [:function, :class] ->
179+
command = commands[{kind, item.label}]
180180
if command do
181181
%{item |
182182
command: command,
@@ -630,7 +630,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
630630
defp from_completion_item(
631631
%{type: :type_spec, metadata: metadata} = suggestion,
632632
_context,
633-
_options
633+
options
634634
) do
635635
%{
636636
name: name,
@@ -656,6 +656,19 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
656656
"#{name}()"
657657
end
658658

659+
signature_help_supported? = Keyword.get(options, :signature_help_supported, false)
660+
signature_after_complete? = Keyword.get(options, :signature_after_complete, true)
661+
662+
trigger_signature? = signature_help_supported? && arity > 1
663+
664+
command =
665+
if trigger_signature? && signature_after_complete? do
666+
%{
667+
"title" => "Trigger Parameter Hint",
668+
"command" => "editor.action.triggerParameterHints"
669+
}
670+
end
671+
659672
%__MODULE__{
660673
label: name,
661674
detail: "typespec #{signature}",
@@ -667,7 +680,8 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
667680
insert_text: snippet,
668681
priority: 10,
669682
kind: :class,
670-
tags: metadata_to_tags(metadata)
683+
tags: metadata_to_tags(metadata),
684+
command: command
671685
}
672686
end
673687

0 commit comments

Comments
 (0)