From e49db11ebf83c1b7cae07b5a34867af0663a4b76 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 15 Nov 2016 16:55:31 +0100 Subject: [PATCH] account for possible modal indexing finish under progress (IDEA-163999), add javadoc (IDEA-CR-15755) --- .../openapi/project/DumbServiceImpl.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java index 950bed627ce3..6ed0750bc5ef 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java @@ -401,8 +401,10 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica runBackgroundProcess(ProgressManager.getInstance().getProgressIndicator(), true)); } finally { - if (myState.get() != State.WAITING_FOR_FINISH) throw new AssertionError(myState.get()); - WriteAction.run(() -> updateFinished(true)); + if (myState.get() != State.SMART) { + if (myState.get() != State.WAITING_FOR_FINISH) throw new AssertionError(myState.get()); + WriteAction.run(() -> updateFinished(true)); + } } } @@ -568,5 +570,26 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica } } - private enum State { SMART, SCHEDULED_TASKS, RUNNING_DUMB_TASKS, WAITING_FOR_FINISH } + private enum State { + /** Non-dumb mode. For all other states, {@link #isDumb()} returns true. */ + SMART, + + /** + * A state between entering dumb mode ({@link #queueTaskOnEdt}) and actually starting the background progress later ({@link #runBackgroundProcess}). + * In this state, it's possible to call {@link #completeJustSubmittedTasks()} and perform all submitted the tasks modally. + * This state can happen after {@link #SMART} or {@link #WAITING_FOR_FINISH}. Followed by {@link #RUNNING_DUMB_TASKS}. + */ + SCHEDULED_TASKS, + + /** + * Indicates that a background thread is currently executing dumb tasks. + */ + RUNNING_DUMB_TASKS, + + /** + * Set after background execution ({@link #RUNNING_DUMB_TASKS}) finishes, until the dumb mode can be exited + * (in a write-safe context on EDT when project is initialized). If new tasks are queued at this state, it's switched to {@link #SCHEDULED_TASKS}. + */ + WAITING_FOR_FINISH + } }