Skip to content

Commit a9a55be

Browse files
committed
trigger signatures for arity 0 functions if there are higher arities available
Fixes #956
1 parent 0fe7b57 commit a9a55be

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,35 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
161161
|> Enum.map(&from_completion_item(&1, context, options))
162162
|> maybe_add_do(context)
163163
|> maybe_add_end(context)
164+
|> Enum.reject(&is_nil/1)
165+
|> sort_items()
166+
167+
# add trigger signatures to arity 0 if there are higher arity completions that would trigger
168+
commands = items
169+
|> Enum.filter(& &1.kind in [:function])
170+
|> Enum.group_by(&{&1.kind, &1.label})
171+
|> Map.new(fn {key, values} ->
172+
command = Enum.find_value(values, & &1.command)
173+
{key, command}
174+
end)
175+
176+
items = items
177+
|> Enum.map(fn
178+
%{command: nil} = item ->
179+
command = commands[{item.kind, item.label}]
180+
if command do
181+
%{item |
182+
command: command,
183+
insert_text: "#{item.label}($1)$0"
184+
}
185+
else
186+
item
187+
end
188+
item -> item
189+
end)
164190

165191
items_json =
166192
items
167-
|> Enum.reject(&is_nil/1)
168-
|> sort_items()
169193
|> items_to_json(options)
170194

171195
{:ok, %{"isIncomplete" => is_incomplete(items_json), "items" => items_json}}

0 commit comments

Comments
 (0)