Skip to content

Commit

Permalink
use async document commit in file opening startup activity
Browse files Browse the repository at this point in the history
  • Loading branch information
donnerpeter committed Apr 21, 2016
1 parent 62fa0ee commit 8a035e0
Showing 1 changed file with 22 additions and 2 deletions.
Expand Up @@ -63,6 +63,7 @@
import com.intellij.openapi.wm.WindowManager;
import com.intellij.openapi.wm.ex.StatusBarEx;
import com.intellij.openapi.wm.impl.IdeFrameImpl;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.reference.SoftReference;
import com.intellij.ui.FocusTrackback;
import com.intellij.ui.docking.DockContainer;
Expand All @@ -71,6 +72,7 @@
import com.intellij.ui.tabs.impl.JBTabsImpl;
import com.intellij.util.Function;
import com.intellij.util.SmartList;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.messages.impl.MessageListenerList;
Expand Down Expand Up @@ -873,7 +875,7 @@ public AsyncFileEditorProvider.Builder compute() {
newProviders = null;
builders = null;
}
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (myProject.isDisposed() || !file.isValid()) {
Expand Down Expand Up @@ -991,7 +993,25 @@ public void run() {
window.setFilePinned(file, pin);
}
}
});
};

if (ApplicationManager.getApplication().isDispatchThread()) {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
runnable.run();
} else {
Semaphore semaphore = new Semaphore();
semaphore.down();
PsiDocumentManager.getInstance(myProject).performLaterWhenAllCommitted(() -> {
try {
runnable.run();
} finally {
semaphore.up();
}
});
//noinspection StatementWithEmptyBody
while (!semaphore.waitFor(10) && !myProject.isDisposed());
}

EditorWithProviderComposite composite = compositeRef.get();
return Pair.create(composite == null ? EMPTY_EDITOR_ARRAY : composite.getEditors(),
composite == null ? EMPTY_PROVIDER_ARRAY : composite.getProviders());
Expand Down

0 comments on commit 8a035e0

Please sign in to comment.