Skip to content

Commit

Permalink
trigger signatures for arity 0 functions if there are higher arities …
Browse files Browse the repository at this point in the history
…available

Fixes #956
  • Loading branch information
lukaszsamson committed Jul 27, 2023
1 parent 0fe7b57 commit a9a55be
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions apps/language_server/lib/language_server/providers/completion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,35 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
|> Enum.map(&from_completion_item(&1, context, options))
|> maybe_add_do(context)
|> maybe_add_end(context)
|> Enum.reject(&is_nil/1)
|> sort_items()

# add trigger signatures to arity 0 if there are higher arity completions that would trigger
commands = items
|> Enum.filter(& &1.kind in [:function])
|> Enum.group_by(&{&1.kind, &1.label})
|> Map.new(fn {key, values} ->
command = Enum.find_value(values, & &1.command)
{key, command}
end)

items = items
|> Enum.map(fn
%{command: nil} = item ->
command = commands[{item.kind, item.label}]
if command do
%{item |
command: command,
insert_text: "#{item.label}($1)$0"
}
else
item
end
item -> item
end)

items_json =
items
|> Enum.reject(&is_nil/1)
|> sort_items()
|> items_to_json(options)

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

0 comments on commit a9a55be

Please sign in to comment.