@@ -249,7 +249,12 @@ defmodule ElixirLS.LanguageServer.Server do
249
249
case state do
250
250
% { analysis_ready?: true , source_files: % { ^ uri => % { dirty?: false } } } ->
251
251
abs_path = SourceFile.Path . absolute_from_uri ( uri , state . project_dir )
252
- { :reply , Dialyzer . suggest_contracts ( [ abs_path ] ) , state }
252
+ parent = self ( )
253
+ spawn ( fn ->
254
+ contracts = Dialyzer . suggest_contracts ( parent , [ abs_path ] )
255
+ GenServer . reply ( from , contracts )
256
+ end )
257
+ { :noreply , state }
253
258
254
259
% { source_files: % { ^ uri => _ } } ->
255
260
# file not saved or analysis not finished
@@ -1521,19 +1526,24 @@ defmodule ElixirLS.LanguageServer.Server do
1521
1526
Map . fetch! ( state . source_files , uri ) . dirty?
1522
1527
end )
1523
1528
1524
- contracts_by_file =
1525
- not_dirty
1526
- |> Enum . map ( fn { _from , uri } -> SourceFile.Path . from_uri ( uri ) end )
1527
- |> Dialyzer . suggest_contracts ( )
1528
- |> Enum . group_by ( fn { file , _ , _ , _ , _ } -> file end )
1529
-
1530
- for { from , uri } <- not_dirty do
1531
- contracts =
1532
- contracts_by_file
1533
- |> Map . get ( SourceFile.Path . from_uri ( uri ) , [ ] )
1534
-
1535
- GenServer . reply ( from , contracts )
1536
- end
1529
+ # Dialyzer.suggest_contracts is blocking and can take a long time to complete
1530
+ # if we block here we hang the server
1531
+ parent = self ( )
1532
+ spawn ( fn ->
1533
+ contracts_by_file =
1534
+ not_dirty
1535
+ |> Enum . map ( fn { _from , uri } -> SourceFile.Path . from_uri ( uri ) end )
1536
+ |> then ( fn uris -> Dialyzer . suggest_contracts ( parent , uris ) end )
1537
+ |> Enum . group_by ( fn { file , _ , _ , _ , _ } -> file end )
1538
+
1539
+ for { from , uri } <- not_dirty do
1540
+ contracts =
1541
+ contracts_by_file
1542
+ |> Map . get ( SourceFile.Path . from_uri ( uri ) , [ ] )
1543
+
1544
+ GenServer . reply ( from , contracts )
1545
+ end
1546
+ end )
1537
1547
1538
1548
% { state | analysis_ready?: true , awaiting_contracts: dirty }
1539
1549
else
0 commit comments