@@ -116,11 +116,44 @@ make_diagnostic(Range, Message, Severity, Source, Data) ->
116
116
117
117
-spec run_diagnostics (uri ()) -> [pid ()].
118
118
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 .
120
127
121
128
% %==============================================================================
122
129
% % Internal Functions
123
130
% %==============================================================================
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 .
124
157
125
158
-spec run_diagnostic (uri (), diagnostic_id ()) -> pid ().
126
159
run_diagnostic (Uri , Id ) ->
0 commit comments