Skip to content

Commit

Permalink
Handle not_found result from docsh (#1198)
Browse files Browse the repository at this point in the history
Also make sure that functions dealing with temporary group leader
here have no chance to get stuck altogether.

Fixes #1177.
  • Loading branch information
keynslug authored Mar 21, 2022
1 parent 2bfcc46 commit 45ab202
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions apps/els_lsp/src/els_docs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,22 @@ edoc(M, F, A) ->
, [doc, spec]]),
flush_group_leader_proxy(GL),

{ok, [{{function, F, A}, _Anno,
_Signature, Desc, _Metadata}|_]} = Res,
format_edoc(Desc)
case Res of
{ok, [{{function, F, A}, _Anno,
_Signature, Desc, _Metadata}|_]} ->
format_edoc(Desc);
{not_found, _} ->
[]
end
catch C:E:ST ->
IO = flush_group_leader_proxy(GL),
?LOG_DEBUG("[hover] Error fetching edoc [error=~p]",
[{M, F, A, C, E, ST, IO}]),
case IO of
timeout ->
[];
noproc ->
[];
IO ->
[{text, IO}]
end
Expand Down Expand Up @@ -389,15 +395,24 @@ setup_group_leader_proxy() ->
-spec flush_group_leader_proxy(pid()) -> [term()] | term().
flush_group_leader_proxy(OrigGL) ->
GL = group_leader(),
Ref = monitor(process, GL),
group_leader(OrigGL, self()),
GL ! {get, Ref, self()},
receive
{Ref, Msg} ->
case GL of
OrigGL ->
% This is the effect of setting a monitor on nonexisting process.
noproc;
_ ->
Ref = monitor(process, GL),
group_leader(OrigGL, self()),
GL ! {get, Ref, self()},
receive
{Ref, Msg} ->
demonitor(Ref, [flush]),
Msg;
{'DOWN', process, Ref, Reason} ->
{'DOWN', process, Ref, Reason} ->
Reason
after 5000 ->
demonitor(Ref, [flush]),
timeout
end
end.

-spec spawn_group_proxy([any()]) -> ok.
Expand Down

0 comments on commit 45ab202

Please sign in to comment.