Skip to content

Commit 0216dc4

Browse files
committed
Don't run diagnostics unless indexing is done
1 parent 01b4afe commit 0216dc4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

apps/els_lsp/src/els_diagnostics.erl

+34-1
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,44 @@ make_diagnostic(Range, Message, Severity, Source, Data) ->
116116

117117
-spec run_diagnostics(uri()) -> [pid()].
118118
run_diagnostics(Uri) ->
119-
[run_diagnostic(Uri, Id) || Id <- enabled_diagnostics()].
119+
case is_initial_indexing_done() of
120+
true ->
121+
ok = wait_for_indexing_job(Uri),
122+
[run_diagnostic(Uri, Id) || Id <- enabled_diagnostics()];
123+
false ->
124+
?LOG_INFO("Initial indexing is not done, skip running diagnostics."),
125+
[]
126+
end.
120127

121128
%%==============================================================================
122129
%% Internal Functions
123130
%%==============================================================================
131+
-spec is_initial_indexing_done() -> boolean().
132+
is_initial_indexing_done() ->
133+
JobTitles = els_background_job:list_titles(),
134+
lists:all(
135+
fun(Job) ->
136+
not lists:member(
137+
<<"Indexing ", Job/binary>>,
138+
JobTitles
139+
)
140+
end,
141+
[<<"Applications">>, <<"OTP">>, <<"Dependencies">>]
142+
).
143+
144+
-spec wait_for_indexing_job(uri()) -> ok.
145+
wait_for_indexing_job(Uri) ->
146+
%% Add delay to allowing indexing job to start
147+
timer:sleep(10),
148+
JobTitles = els_background_job:list_titles(),
149+
case lists:member(<<"Indexing ", Uri/binary>>, JobTitles) of
150+
false ->
151+
%% No indexing job is running, we're ready!
152+
ok;
153+
true ->
154+
%% Indexing job is still running, retry until it finishes
155+
wait_for_indexing_job(Uri)
156+
end.
124157

125158
-spec run_diagnostic(uri(), diagnostic_id()) -> pid().
126159
run_diagnostic(Uri, Id) ->

apps/els_lsp/src/els_indexing.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ start(Group, Skip, SkipTag, Entries, Source) ->
249249
},
250250
?LOG_INFO(
251251
"Completed indexing for ~s "
252-
"(succeeded: ~p, skipped: ~p, failed: ~p)",
253-
[Group, Succeeded, Skipped, Failed]
252+
"(succeeded: ~p, skipped: ~p, failed: ~p, duration: ~p ms)",
253+
[Group, Succeeded, Skipped, Failed, Duration]
254254
),
255255
els_telemetry:send_notification(Event)
256256
end

0 commit comments

Comments
 (0)