Skip to content

Commit abbe6f5

Browse files
authored
[CQ] stop blocking on FlutterPluginsLibraryManager update (#8094)
See: #8089 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
1 parent 12f8294 commit abbe6f5

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

flutter-idea/src/io/flutter/pub/PubRoots.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static List<PubRoot> forModule(@NotNull Module module) {
4848
* (Based on the filesystem cache; doesn't refresh anything.)
4949
*/
5050
@NotNull
51-
public static List<PubRoot> forProject(@NotNull Project project) {
51+
public static List<@NotNull PubRoot> forProject(@NotNull Project project) {
5252
final List<PubRoot> result = new ArrayList<>();
5353
if (project.isDisposed()) return result;
5454

flutter-idea/src/io/flutter/sdk/FlutterPluginsLibraryManager.java

+19-8
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
import com.intellij.openapi.application.ApplicationManager;
99
import com.intellij.openapi.application.ModalityState;
10+
import com.intellij.openapi.application.ReadAction;
1011
import com.intellij.openapi.project.DumbService;
1112
import com.intellij.openapi.project.Project;
1213
import com.intellij.openapi.roots.ModuleRootEvent;
1314
import com.intellij.openapi.roots.ModuleRootListener;
1415
import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
1516
import com.intellij.openapi.vfs.*;
17+
import com.intellij.util.concurrency.AppExecutorUtil;
1618
import com.jetbrains.lang.dart.util.DotPackagesFileUtil;
19+
import io.flutter.dart.FlutterDartAnalysisServer;
1720
import io.flutter.pub.PubRoot;
1821
import io.flutter.pub.PubRoots;
1922
import org.jetbrains.annotations.NotNull;
@@ -97,7 +100,7 @@ private void scheduleUpdate() {
97100
}
98101

99102
final Runnable runnable = this::updateFlutterPlugins;
100-
DumbService.getInstance(getProject()).smartInvokeLater(runnable, ModalityState.NON_MODAL);
103+
DumbService.getInstance(getProject()).smartInvokeLater(runnable, ModalityState.nonModal());
101104
}
102105

103106
private void updateFlutterPlugins() {
@@ -114,15 +117,22 @@ private void updateFlutterPlugins() {
114117
}
115118

116119
private void updateFlutterPluginsImpl() {
117-
final Set<String> flutterPluginPaths = getFlutterPluginPaths(PubRoots.forProject(getProject()));
118-
final Set<String> flutterPluginUrls = new HashSet<>();
119-
for (String path : flutterPluginPaths) {
120-
flutterPluginUrls.add(VfsUtilCore.pathToUrl(path));
121-
}
122-
updateLibraryContent(flutterPluginUrls);
120+
Project project = getProject();
121+
122+
ReadAction.nonBlocking(() -> getFlutterPluginPaths(PubRoots.forProject(project)))
123+
.expireWith(FlutterDartAnalysisServer.getInstance(project))
124+
.finishOnUiThread(ModalityState.nonModal(), flutterPluginPaths -> {
125+
if (flutterPluginPaths == null) return;
126+
final Set<String> flutterPluginUrls = new HashSet<>();
127+
for (String path : flutterPluginPaths) {
128+
flutterPluginUrls.add(VfsUtilCore.pathToUrl(path));
129+
}
130+
updateLibraryContent(flutterPluginUrls);
131+
})
132+
.submit(AppExecutorUtil.getAppExecutorService());
123133
}
124134

125-
private static Set<String> getFlutterPluginPaths(List<PubRoot> roots) {
135+
private static @NotNull Set<@NotNull String> getFlutterPluginPaths(@NotNull List<@NotNull PubRoot> roots) {
126136
final Set<String> paths = new HashSet<>();
127137

128138
for (PubRoot pubRoot : roots) {
@@ -132,6 +142,7 @@ private static Set<String> getFlutterPluginPaths(List<PubRoot> roots) {
132142
}
133143

134144
for (String packagePath : packagesMap.values()) {
145+
if (packagePath == null) continue;;
135146
final VirtualFile libFolder = LocalFileSystem.getInstance().findFileByPath(packagePath);
136147
if (libFolder == null) {
137148
continue;

0 commit comments

Comments
 (0)