From 162c8ec9147fb9c164db74041d8680db5ffa0712 Mon Sep 17 00:00:00 2001 From: Jaime Wren Date: Wed, 8 Jan 2025 11:26:59 -0800 Subject: [PATCH] Fix the slow operation notification associated with PubRoot (#7885) This resolves https://github.com/flutter/flutter-intellij/issues/7792 --- flutter-idea/src/io/flutter/pub/PubRoot.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/flutter-idea/src/io/flutter/pub/PubRoot.java b/flutter-idea/src/io/flutter/pub/PubRoot.java index c5cff6fad..278529c5b 100644 --- a/flutter-idea/src/io/flutter/pub/PubRoot.java +++ b/flutter-idea/src/io/flutter/pub/PubRoot.java @@ -9,6 +9,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; @@ -18,6 +19,7 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; +import com.intellij.util.concurrency.AppExecutorUtil; import com.jetbrains.lang.dart.util.DotPackagesFileUtil; import io.flutter.FlutterUtils; import org.jetbrains.annotations.NotNull; @@ -139,13 +141,20 @@ public static PubRoot forDirectory(@Nullable VirtualFile dir) { if (dir == null || !dir.isDirectory() || dir.getPath().endsWith("/")) { return null; } + VirtualFile pubspec = null; + try { + pubspec = ReadAction.nonBlocking(() -> { + return dir.findChild(PUBSPEC_YAML); + }).submit(AppExecutorUtil.getAppExecutorService()).get(); + } catch (Exception e) { + // do nothing + } - final VirtualFile pubspec = dir.findChild(PUBSPEC_YAML); if (pubspec == null || !pubspec.exists() || pubspec.isDirectory()) { return null; + } else { + return new PubRoot(dir, pubspec); } - - return new PubRoot(dir, pubspec); } /**