Skip to content

[CQ] stop blocking on FlutterPluginsLibraryManager update #8094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flutter-idea/src/io/flutter/pub/PubRoots.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static List<PubRoot> forModule(@NotNull Module module) {
* (Based on the filesystem cache; doesn't refresh anything.)
*/
@NotNull
public static List<PubRoot> forProject(@NotNull Project project) {
public static List<@NotNull PubRoot> forProject(@NotNull Project project) {
final List<PubRoot> result = new ArrayList<>();
if (project.isDisposed()) return result;

Expand Down
27 changes: 19 additions & 8 deletions flutter-idea/src/io/flutter/sdk/FlutterPluginsLibraryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
import com.intellij.openapi.vfs.*;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.jetbrains.lang.dart.util.DotPackagesFileUtil;
import io.flutter.dart.FlutterDartAnalysisServer;
import io.flutter.pub.PubRoot;
import io.flutter.pub.PubRoots;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -97,7 +100,7 @@ private void scheduleUpdate() {
}

final Runnable runnable = this::updateFlutterPlugins;
DumbService.getInstance(getProject()).smartInvokeLater(runnable, ModalityState.NON_MODAL);
DumbService.getInstance(getProject()).smartInvokeLater(runnable, ModalityState.nonModal());
}

private void updateFlutterPlugins() {
Expand All @@ -114,15 +117,22 @@ private void updateFlutterPlugins() {
}

private void updateFlutterPluginsImpl() {
final Set<String> flutterPluginPaths = getFlutterPluginPaths(PubRoots.forProject(getProject()));
final Set<String> flutterPluginUrls = new HashSet<>();
for (String path : flutterPluginPaths) {
flutterPluginUrls.add(VfsUtilCore.pathToUrl(path));
}
updateLibraryContent(flutterPluginUrls);
Project project = getProject();

ReadAction.nonBlocking(() -> getFlutterPluginPaths(PubRoots.forProject(project)))
.expireWith(FlutterDartAnalysisServer.getInstance(project))
.finishOnUiThread(ModalityState.nonModal(), flutterPluginPaths -> {
if (flutterPluginPaths == null) return;
final Set<String> flutterPluginUrls = new HashSet<>();
for (String path : flutterPluginPaths) {
flutterPluginUrls.add(VfsUtilCore.pathToUrl(path));
}
updateLibraryContent(flutterPluginUrls);
})
.submit(AppExecutorUtil.getAppExecutorService());
}

private static Set<String> getFlutterPluginPaths(List<PubRoot> roots) {
private static @NotNull Set<@NotNull String> getFlutterPluginPaths(@NotNull List<@NotNull PubRoot> roots) {
final Set<String> paths = new HashSet<>();

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

for (String packagePath : packagesMap.values()) {
if (packagePath == null) continue;;
final VirtualFile libFolder = LocalFileSystem.getInstance().findFileByPath(packagePath);
if (libFolder == null) {
continue;
Expand Down