From d4203a3c78f74dd2f43763190ba5ef6f78112a3e Mon Sep 17 00:00:00 2001 From: Peter Gromov Date: Tue, 16 Jun 2020 12:11:25 +0200 Subject: [PATCH] IDEA-242883 IncorrectOperationException: You must not call performWhenAllCommitted()/cancelAndRunWhenCommitted() from within after-commit handler GitOrigin-RevId: cb446ac71163bf4677072d0136408d812d204dd7 --- .../src/com/intellij/psi/PsiDocumentManager.java | 10 ++++++++++ .../com/intellij/psi/impl/PsiDocumentManagerBase.java | 2 +- .../ide/util/treeView/AbstractTreeStructure.java | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/platform/core-api/src/com/intellij/psi/PsiDocumentManager.java b/platform/core-api/src/com/intellij/psi/PsiDocumentManager.java index 01adcbf9f50d..7729a3366db3 100644 --- a/platform/core-api/src/com/intellij/psi/PsiDocumentManager.java +++ b/platform/core-api/src/com/intellij/psi/PsiDocumentManager.java @@ -6,6 +6,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -156,6 +157,15 @@ public abstract class PsiDocumentManager { */ public abstract boolean hasUncommitedDocuments(); + /** + * @return if any modified documents with event-system-enabled PSI have not been committed. + * @see FileViewProvider#isEventSystemEnabled() + */ + @ApiStatus.Experimental + public boolean hasEventSystemEnabledUncommittedDocuments() { + return hasUncommitedDocuments(); + } + /** * Commits the documents and runs the specified operation, which does not return a value, in a read action. * Can be called from a thread other than the Swing dispatch thread. diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java index 454477eb8c0c..be5b23df7726 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java @@ -705,7 +705,7 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen !hasEventSystemEnabledUncommittedDocuments(); } - @ApiStatus.Internal + @Override public boolean hasEventSystemEnabledUncommittedDocuments() { return ContainerUtil.exists(myUncommittedDocuments, this::isEventSystemEnabled); } diff --git a/platform/editor-ui-api/src/com/intellij/ide/util/treeView/AbstractTreeStructure.java b/platform/editor-ui-api/src/com/intellij/ide/util/treeView/AbstractTreeStructure.java index 74330a6277d3..0385c5fc8c2e 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/util/treeView/AbstractTreeStructure.java +++ b/platform/editor-ui-api/src/com/intellij/ide/util/treeView/AbstractTreeStructure.java @@ -27,7 +27,7 @@ public abstract class AbstractTreeStructure { public static ActionCallback asyncCommitDocuments(@NotNull Project project) { if (project.isDisposed()) return ActionCallback.DONE; PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); - if (!documentManager.hasUncommitedDocuments()) { + if (!documentManager.hasEventSystemEnabledUncommittedDocuments()) { return ActionCallback.DONE; } final ActionCallback callback = new ActionCallback();