Skip to content

Commit 8a22882

Browse files
authored
Fix awaiting_contracts not getting responses (#433)
* do not add amore awaiting contracts for the same uri * there should not be any awaiting contracts for not open uris * group by to avoid multiple filtering
1 parent 3b2c51b commit 8a22882

File tree

1 file changed

+15
-14
lines changed
  • apps/language_server/lib/language_server

1 file changed

+15
-14
lines changed

apps/language_server/lib/language_server/server.ex

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ defmodule ElixirLS.LanguageServer.Server do
124124
{:reply, Dialyzer.suggest_contracts([SourceFile.path_from_uri(uri)]), state}
125125

126126
_ ->
127-
{:noreply, %{state | awaiting_contracts: [{from, uri} | state.awaiting_contracts]}}
127+
awaiting_contracts = reject_awaiting_contracts(state.awaiting_contracts, uri)
128+
129+
{:noreply, %{state | awaiting_contracts: [{from, uri} | awaiting_contracts]}}
128130
end
129131
end
130132

@@ -339,11 +341,7 @@ defmodule ElixirLS.LanguageServer.Server do
339341

340342
state
341343
else
342-
awaiting_contracts =
343-
Enum.reject(state.awaiting_contracts, fn
344-
{from, ^uri} -> GenServer.reply(from, [])
345-
_ -> false
346-
end)
344+
awaiting_contracts = reject_awaiting_contracts(state.awaiting_contracts, uri)
347345

348346
%{
349347
state
@@ -876,24 +874,20 @@ defmodule ElixirLS.LanguageServer.Server do
876874

877875
{dirty, not_dirty} =
878876
state.awaiting_contracts
879-
|> Enum.filter(fn {_, uri} ->
880-
state.source_files[uri] != nil
881-
end)
882877
|> Enum.split_with(fn {_, uri} ->
883878
state.source_files[uri].dirty?
884879
end)
885880

886-
contracts =
881+
contracts_by_file =
887882
not_dirty
888-
|> Enum.uniq()
889883
|> Enum.map(fn {_from, uri} -> SourceFile.path_from_uri(uri) end)
890884
|> Dialyzer.suggest_contracts()
885+
|> Enum.group_by(fn {file, _, _, _, _} -> file end)
891886

892887
for {from, uri} <- not_dirty do
893888
contracts =
894-
Enum.filter(contracts, fn {file, _, _, _, _} ->
895-
SourceFile.path_from_uri(uri) == file
896-
end)
889+
contracts_by_file
890+
|> Map.get(SourceFile.path_from_uri(uri), [])
897891

898892
GenServer.reply(from, contracts)
899893
end
@@ -1087,4 +1081,11 @@ defmodule ElixirLS.LanguageServer.Server do
10871081
source_file
10881082
end
10891083
end
1084+
1085+
defp reject_awaiting_contracts(awaiting_contracts, uri) do
1086+
Enum.reject(awaiting_contracts, fn
1087+
{from, ^uri} -> GenServer.reply(from, [])
1088+
_ -> false
1089+
end)
1090+
end
10901091
end

0 commit comments

Comments
 (0)