From 0216dc4c0778a53a36e78e050feb89085763c995 Mon Sep 17 00:00:00 2001 From: Hakan Nilsson Date: Sat, 5 Oct 2024 22:42:11 +0200 Subject: [PATCH] Don't run diagnostics unless indexing is done --- apps/els_lsp/src/els_diagnostics.erl | 35 +++++++++++++++++++++++++++- apps/els_lsp/src/els_indexing.erl | 4 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/apps/els_lsp/src/els_diagnostics.erl b/apps/els_lsp/src/els_diagnostics.erl index 8cfb101a..1184f4a1 100644 --- a/apps/els_lsp/src/els_diagnostics.erl +++ b/apps/els_lsp/src/els_diagnostics.erl @@ -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) -> diff --git a/apps/els_lsp/src/els_indexing.erl b/apps/els_lsp/src/els_indexing.erl index cf793027..c72dca7f 100644 --- a/apps/els_lsp/src/els_indexing.erl +++ b/apps/els_lsp/src/els_indexing.erl @@ -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