Skip to content

Commit

Permalink
Fix the issue of Zed and Emacs not being able to autocomplete due to …
Browse files Browse the repository at this point in the history
…`{ isIncomplete: false, items }`.

According to this explanation:

> result: CompletionItem[] | CompletionList | null. If a CompletionItem[] is provided, it is interpreted as complete. So it is the same as { isIncomplete: false, items }.

I suspect that many clients do not handle the situation of `{ isIncomplete: false, items }`.
They default to only handling `CompletionItem[]`.
  • Loading branch information
scottming authored and zachallaun committed Oct 16, 2023
1 parent ee4e752 commit e2feb49
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions apps/server/lib/lexical/server/code_intelligence/completion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ defmodule Lexical.Server.CodeIntelligence.Completion do
{:ok, env} ->
completions = completions(project, env, context)
Logger.info("Emitting completions: #{inspect(completions)}")
completion_list(completions)
maybe_to_completion_list(completions)

{:error, _} = error ->
Logger.error("Failed to build completion env #{inspect(error)}")
completion_list()
maybe_to_completion_list()
end
end

Expand Down Expand Up @@ -245,7 +245,11 @@ defmodule Lexical.Server.CodeIntelligence.Completion do
true
end

defp completion_list(items \\ []) do
Completion.List.new(items: items, is_incomplete: items == [])
defp maybe_to_completion_list(items \\ [])

defp maybe_to_completion_list([]) do
Completion.List.new(items: [], is_incomplete: true)
end

defp maybe_to_completion_list(items), do: items
end

0 comments on commit e2feb49

Please sign in to comment.