Skip to content

Commit

Permalink
Don't run diagnostics unless indexing is done
Browse files Browse the repository at this point in the history
  • Loading branch information
plux committed Oct 5, 2024
1 parent 01b4afe commit 0216dc4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
35 changes: 34 additions & 1 deletion apps/els_lsp/src/els_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,44 @@ make_diagnostic(Range, Message, Severity, Source, Data) ->

-spec run_diagnostics(uri()) -> [pid()].
run_diagnostics(Uri) ->
[run_diagnostic(Uri, Id) || Id <- enabled_diagnostics()].
case is_initial_indexing_done() of
true ->
ok = wait_for_indexing_job(Uri),
[run_diagnostic(Uri, Id) || Id <- enabled_diagnostics()];
false ->
?LOG_INFO("Initial indexing is not done, skip running diagnostics."),
[]
end.

%%==============================================================================
%% Internal Functions
%%==============================================================================
-spec is_initial_indexing_done() -> boolean().
is_initial_indexing_done() ->
JobTitles = els_background_job:list_titles(),
lists:all(
fun(Job) ->
not lists:member(
<<"Indexing ", Job/binary>>,
JobTitles
)
end,
[<<"Applications">>, <<"OTP">>, <<"Dependencies">>]
).

-spec wait_for_indexing_job(uri()) -> ok.
wait_for_indexing_job(Uri) ->
%% Add delay to allowing indexing job to start
timer:sleep(10),
JobTitles = els_background_job:list_titles(),
case lists:member(<<"Indexing ", Uri/binary>>, JobTitles) of
false ->
%% No indexing job is running, we're ready!
ok;
true ->
%% Indexing job is still running, retry until it finishes
wait_for_indexing_job(Uri)
end.

-spec run_diagnostic(uri(), diagnostic_id()) -> pid().
run_diagnostic(Uri, Id) ->
Expand Down
4 changes: 2 additions & 2 deletions apps/els_lsp/src/els_indexing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ start(Group, Skip, SkipTag, Entries, Source) ->
},
?LOG_INFO(
"Completed indexing for ~s "
"(succeeded: ~p, skipped: ~p, failed: ~p)",
[Group, Succeeded, Skipped, Failed]
"(succeeded: ~p, skipped: ~p, failed: ~p, duration: ~p ms)",
[Group, Succeeded, Skipped, Failed, Duration]
),
els_telemetry:send_notification(Event)
end
Expand Down

0 comments on commit 0216dc4

Please sign in to comment.