28
28
import com .github ._1c_syntax .bsl .languageserver .utils .Resources ;
29
29
import lombok .RequiredArgsConstructor ;
30
30
import org .springframework .context .event .EventListener ;
31
+ import org .springframework .scheduling .annotation .Async ;
31
32
import org .springframework .stereotype .Component ;
32
33
34
+ import java .util .concurrent .ExecutionException ;
35
+ import java .util .concurrent .ForkJoinPool ;
36
+
33
37
/**
34
38
* Перехватчик события заполнения контекста сервера, запускающий анализ всех файлов контекста.
35
39
*/
@@ -42,6 +46,7 @@ public class AnalyzeProjectOnStart {
42
46
private final WorkDoneProgressHelper workDoneProgressHelper ;
43
47
44
48
@ EventListener
49
+ @ Async
45
50
public void handleEvent (ServerContextPopulatedEvent event ) {
46
51
if (!configuration .getDiagnosticsOptions ().isAnalyzeOnStart ()) {
47
52
return ;
@@ -53,16 +58,28 @@ public void handleEvent(ServerContextPopulatedEvent event) {
53
58
var progress = workDoneProgressHelper .createProgress (documentContexts .size (), getMessage ("filesSuffix" ));
54
59
progress .beginProgress (getMessage ("analyzeProject" ));
55
60
56
- documentContexts . forEach (( DocumentContext documentContext ) -> {
61
+ var executorService = new ForkJoinPool ( ForkJoinPool . getCommonPoolParallelism ());
57
62
58
- progress .tick ();
63
+ try {
64
+ executorService .submit (() ->
65
+ documentContexts .parallelStream ().forEach ((DocumentContext documentContext ) -> {
66
+ progress .tick ();
59
67
60
- serverContext .rebuildDocument (documentContext );
61
- diagnosticProvider .computeAndPublishDiagnostics (documentContext );
68
+ serverContext .rebuildDocument (documentContext );
69
+ diagnosticProvider .computeAndPublishDiagnostics (documentContext );
62
70
63
- serverContext .tryClearDocument (documentContext );
71
+ serverContext .tryClearDocument (documentContext );
72
+ })
73
+ ).get ();
64
74
65
- });
75
+ } catch (ExecutionException e ) {
76
+ throw new RuntimeException ("Can't analyze project on start" , e );
77
+ } catch (InterruptedException e ) {
78
+ Thread .currentThread ().interrupt ();
79
+ throw new RuntimeException ("Interrupted while analyzing project on start" , e );
80
+ } finally {
81
+ executorService .shutdown ();
82
+ }
66
83
67
84
progress .endProgress (getMessage ("projectAnalyzed" ));
68
85
}
0 commit comments