@@ -124,7 +124,9 @@ defmodule ElixirLS.LanguageServer.Server do
124
124
{ :reply , Dialyzer . suggest_contracts ( [ SourceFile . path_from_uri ( uri ) ] ) , state }
125
125
126
126
_ ->
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 ] } }
128
130
end
129
131
end
130
132
@@ -339,11 +341,7 @@ defmodule ElixirLS.LanguageServer.Server do
339
341
340
342
state
341
343
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 )
347
345
348
346
% {
349
347
state
@@ -876,24 +874,20 @@ defmodule ElixirLS.LanguageServer.Server do
876
874
877
875
{ dirty , not_dirty } =
878
876
state . awaiting_contracts
879
- |> Enum . filter ( fn { _ , uri } ->
880
- state . source_files [ uri ] != nil
881
- end )
882
877
|> Enum . split_with ( fn { _ , uri } ->
883
878
state . source_files [ uri ] . dirty?
884
879
end )
885
880
886
- contracts =
881
+ contracts_by_file =
887
882
not_dirty
888
- |> Enum . uniq ( )
889
883
|> Enum . map ( fn { _from , uri } -> SourceFile . path_from_uri ( uri ) end )
890
884
|> Dialyzer . suggest_contracts ( )
885
+ |> Enum . group_by ( fn { file , _ , _ , _ , _ } -> file end )
891
886
892
887
for { from , uri } <- not_dirty do
893
888
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 ) , [ ] )
897
891
898
892
GenServer . reply ( from , contracts )
899
893
end
@@ -1087,4 +1081,11 @@ defmodule ElixirLS.LanguageServer.Server do
1087
1081
source_file
1088
1082
end
1089
1083
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
1090
1091
end
0 commit comments