@@ -139,6 +139,8 @@ public class GraphQLConfigManager {
139
139
private final Lock writeLock = cacheLock .writeLock ();
140
140
private final Lock readLock = cacheLock .readLock ();
141
141
142
+ private final Ref <Runnable > buildConfigurationModelCallable = Ref .create ();
143
+
142
144
public GraphQLConfigManager (Project myProject ) {
143
145
this .myProject = myProject ;
144
146
this .projectScope = GlobalSearchScope .projectScope (myProject );
@@ -487,17 +489,41 @@ private boolean hasGraphQLConfigComment(PsiElement psiElement) {
487
489
*/
488
490
public void buildConfigurationModel (@ Nullable List <VirtualFile > changedConfigurationFiles , @ Nullable Runnable onCompleted ) {
489
491
ApplicationManager .getApplication ().invokeLater (() -> {
492
+
493
+ // runs on the UI thread so task scheduling can be considered atomic
494
+ final boolean hasExistingTask = buildConfigurationModelCallable .get () != null ;
495
+
496
+ // set the runnable that the task uses to the latest refresh info
497
+ buildConfigurationModelCallable .set (() -> {
498
+ doBuildConfigurationModel (changedConfigurationFiles );
499
+ if (onCompleted != null ) {
500
+ onCompleted .run ();
501
+ }
502
+ });
503
+
504
+ if (hasExistingTask ) {
505
+ // already queued up the task
506
+ return ;
507
+ }
508
+
490
509
final Task .Backgroundable task = new Task .Backgroundable (myProject , "GraphQL Configuration Scan" , false ) {
491
510
@ Override
492
511
public void run (@ NotNull ProgressIndicator indicator ) {
493
512
indicator .setIndeterminate (true );
494
513
DumbService .getInstance (myProject ).runReadActionInSmartMode (() -> {
495
- doBuildConfigurationModel ( changedConfigurationFiles );
496
- if (onCompleted != null ) {
497
- onCompleted .run ();
514
+ final Runnable runnable = buildConfigurationModelCallable . get ( );
515
+ if (runnable != null ) {
516
+ runnable .run ();
498
517
}
499
518
});
500
519
}
520
+
521
+ @ Override
522
+ public void onFinished () {
523
+ // also called on UI thread
524
+ buildConfigurationModelCallable .set (null );
525
+ }
526
+
501
527
};
502
528
if (!myProject .isDisposed ()) {
503
529
ProgressManager .getInstance ().run (task );
0 commit comments