Skip to content

Commit 03a1ec7

Browse files
committed
Resolves a "Slow operations are prohibited on EDT" exceptions
This resolves #8447 and #8446 Additional work may be needed to limit the number of read actions by the plugin, see #8242
1 parent 53d3b61 commit 03a1ec7

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/io/flutter/utils/FlutterModuleUtils.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -277,28 +277,31 @@ public static void autoCreateRunConfig(@NotNull Project project, @NotNull PubRoo
277277
public static void autoShowMain(@NotNull Project project, @NotNull PubRoot root) {
278278
if (project.isDisposed()) return;
279279

280-
final VirtualFile main = root.getFileToOpen();
281-
if (main == null) return;
280+
// Offload the slow file system lookup to a background thread.
281+
ApplicationManager.getApplication().executeOnPooledThread(() -> {
282+
final VirtualFile main = root.getFileToOpen();
282283

283-
DumbService.getInstance(project).runWhenSmart(() -> {
284-
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
285-
if (fileEditorManager == null) {
286-
return;
287-
}
288-
FileEditor[] editors = fileEditorManager.getAllEditors();
289-
if (editors.length > 1) {
290-
return;
291-
}
292-
for (FileEditor editor : editors) {
293-
if (editor == null) {
294-
return;
295-
}
296-
VirtualFile file = editor.getFile();
297-
if (file != null && file.equals(main) && FlutterUtils.isDartFile(file)) {
298-
return;
299-
}
284+
// If the file is found, switch back to the EDT to safely update the UI.
285+
if (main != null && main.exists() && !main.isDirectory()) {
286+
DumbService.getInstance(project).runWhenSmart(() -> {
287+
if (project.isDisposed()) return;
288+
289+
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
290+
if (fileEditorManager == null) return;
291+
292+
FileEditor[] editors = fileEditorManager.getAllEditors();
293+
if (editors.length > 1) return;
294+
295+
for (FileEditor editor : editors) {
296+
if (editor == null) return;
297+
298+
VirtualFile file = editor.getFile();
299+
if (file != null && file.equals(main) && FlutterUtils.isDartFile(file)) return;
300+
}
301+
302+
fileEditorManager.openFile(main, editors.length == 0);
303+
});
300304
}
301-
fileEditorManager.openFile(main, editors.length == 0);
302305
});
303306
}
304307

0 commit comments

Comments
 (0)