@@ -277,28 +277,31 @@ public static void autoCreateRunConfig(@NotNull Project project, @NotNull PubRoo
277
277
public static void autoShowMain (@ NotNull Project project , @ NotNull PubRoot root ) {
278
278
if (project .isDisposed ()) return ;
279
279
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 ();
282
283
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
+ });
300
304
}
301
- fileEditorManager .openFile (main , editors .length == 0 );
302
305
});
303
306
}
304
307
0 commit comments