7
7
8
8
import com .google .common .base .Objects ;
9
9
import com .google .common .collect .ImmutableSet ;
10
+ import com .intellij .openapi .application .ReadAction ;
10
11
import com .intellij .openapi .diagnostic .Logger ;
11
12
import com .intellij .openapi .project .Project ;
12
13
import com .intellij .openapi .util .registry .Registry ;
14
+ import com .intellij .util .concurrency .AppExecutorUtil ;
13
15
import io .flutter .FlutterUtils ;
16
+ import io .flutter .dart .FlutterDartAnalysisServer ;
14
17
import io .flutter .project .ProjectWatch ;
15
18
import io .flutter .utils .FileWatch ;
16
19
import org .jetbrains .annotations .NotNull ;
17
20
import org .jetbrains .annotations .Nullable ;
18
21
19
- import javax .swing .*;
20
22
import java .util .LinkedHashSet ;
21
23
import java .util .Set ;
22
24
import java .util .concurrent .atomic .AtomicReference ;
@@ -35,7 +37,7 @@ public class WorkspaceCache {
35
37
36
38
private boolean refreshScheduled = false ;
37
39
38
- private final Set <Runnable > subscribers = new LinkedHashSet <>();
40
+ private final @ NotNull Set <@ NotNull Runnable > subscribers = new LinkedHashSet <>();
39
41
40
42
private WorkspaceCache (@ NotNull final Project project ) {
41
43
this .project = project ;
@@ -44,7 +46,7 @@ private WorkspaceCache(@NotNull final Project project) {
44
46
// dartProjectsWithoutPubspecRegistryKey registry key.
45
47
//
46
48
// https://github.com/flutter/flutter-intellij/issues/7333
47
- if (Registry .is (dartProjectsWithoutPubspecRegistryKey , false )) {
49
+ if (Registry .is (dartProjectsWithoutPubspecRegistryKey , false )) {
48
50
this .cache = null ;
49
51
return ;
50
52
}
@@ -78,13 +80,15 @@ private void scheduleRefresh() {
78
80
return ;
79
81
}
80
82
refreshScheduled = true ;
81
- SwingUtilities .invokeLater (() -> {
82
- refreshScheduled = false ;
83
- if (project .isDisposed ()) {
84
- return ;
85
- }
86
- refresh ();
87
- });
83
+ ReadAction .nonBlocking (() -> {
84
+ refreshScheduled = false ;
85
+ if (!project .isDisposed ()) {
86
+ refresh ();
87
+ }
88
+ return null ;
89
+ })
90
+ .expireWith (FlutterDartAnalysisServer .getInstance (project ))
91
+ .submit (AppExecutorUtil .getAppExecutorService ());
88
92
}
89
93
90
94
@ NotNull
@@ -112,7 +116,7 @@ public boolean isBazel() {
112
116
/**
113
117
* Runs a callback each time the current Workspace changes.
114
118
*/
115
- public void subscribe (Runnable callback ) {
119
+ public void subscribe (@ NotNull Runnable callback ) {
116
120
synchronized (subscribers ) {
117
121
subscribers .add (callback );
118
122
}
@@ -152,7 +156,7 @@ private void refresh() {
152
156
notifyListeners ();
153
157
}
154
158
155
- private Set <Runnable > getSubscribers () {
159
+ private Set <@ NotNull Runnable > getSubscribers () {
156
160
synchronized (subscribers ) {
157
161
return ImmutableSet .copyOf (subscribers );
158
162
}
0 commit comments