public abstract class DumbService
extends java.lang.Object
DumbAware
interface.
"Dumb" mode starts and ends in a WriteAction
, so if you're inside a ReadAction
on a background thread, it won't suddenly begin in the middle of your operation. But note that whenever you start
a top-level read action on a background thread, you should be prepared to anything being changed, including "dumb"
mode being suddenly on and off. To avoid executing a read action in "dumb" mode, please use runReadActionInSmartMode(com.intellij.openapi.util.Computable<T>)
or
NonBlockingReadAction.inSmartMode(com.intellij.openapi.project.Project)
.
More information about dumb mode could be found here: IndexNotReadyException
Modifier and Type | Class and Description |
---|---|
static interface |
DumbService.DumbModeListener |
Modifier and Type | Field and Description |
---|---|
static Topic<DumbService.DumbModeListener> |
DUMB_MODE |
Constructor and Description |
---|
DumbService() |
Modifier and Type | Method and Description |
---|---|
static void |
allowStartingDumbModeInside(DumbModePermission permission,
java.lang.Runnable runnable)
Deprecated.
Obsolete, does nothing, just executes the passed runnable.
|
abstract void |
cancelAllTasksAndWait()
Cancels all tasks and wait when their execution is finished.
|
abstract void |
cancelTask(DumbModeTask task)
Cancels the given task.
|
abstract void |
completeJustSubmittedTasks()
Runs the "just submitted" tasks under a modal dialog.
|
<T,E extends java.lang.Throwable> |
computeWithAlternativeResolveEnabled(ThrowableComputable<T,E> runnable)
Invokes the given computable with alternative resolve set to true.
|
<T> java.util.List<T> |
filterByDumbAwareness(java.util.Collection<? extends T> collection) |
<T> java.util.List<T> |
filterByDumbAwareness(T [] array) |
static <T> java.util.List<T> |
getDumbAwareExtensions(Project project,
ExtensionPointName<T> extensionPoint) |
static <T> java.util.List<T> |
getDumbAwareExtensions(Project project,
ProjectExtensionPointName<T> extensionPoint) |
static DumbService |
getInstance(Project project) |
abstract ModificationTracker |
getModificationTracker()
The tracker is advanced each time we enter/exit from dumb mode.
|
abstract Project |
getProject() |
abstract boolean |
isAlternativeResolveEnabled() |
abstract boolean |
isDumb()
To avoid race conditions use it only in EDT thread or inside read-action.
|
static boolean |
isDumb(Project project) |
static boolean |
isDumbAware(java.lang.Object o) |
abstract boolean |
isSuspendedDumbMode()
Checks whether
isDumb() is true for the current project and if it's currently suspended by user or a suspendIndexingAndRun(java.lang.String, java.lang.Runnable) call. |
void |
makeDumbAware(javax.swing.JComponent componentToDisable,
Disposable parentDisposable)
Disables given component temporarily during dumb mode.
|
abstract void |
queueTask(DumbModeTask task)
Queues a task to be executed in "dumb mode", where access to indexes is forbidden.
|
void |
repeatUntilPassesInSmartMode(java.lang.Runnable r)
Deprecated.
This method provides no guarantees and should be avoided, please use
runReadActionInSmartMode(com.intellij.openapi.util.Computable<T>) instead. |
<T> T |
runReadActionInSmartMode(Computable<T> r)
Pause the current thread until dumb mode ends, and then run the read action.
|
void |
runReadActionInSmartMode(java.lang.Runnable r)
Pause the current thread until dumb mode ends, and then run the read action.
|
abstract void |
runWhenSmart(java.lang.Runnable runnable)
Executes the runnable as soon as possible on AWT Event Dispatch when:
project is initialized
and there's no dumb mode in progress
This may also happen immediately if these conditions are already met.
Note that it's not guaranteed that the dumb mode won't start again during this runnable execution, it should manage that situation explicitly.
|
<E extends java.lang.Throwable> |
runWithAlternativeResolveEnabled(ThrowableRunnable<E> runnable)
Invokes the given runnable with alternative resolve set to true.
|
abstract void |
setAlternativeResolveEnabled(boolean enabled)
|
abstract boolean |
showDumbModeDialog(java.util.List<java.lang.String> actionNames)
Show modal progress about indexing blocking those actions until it is cancelled or indexing stops.
|
abstract void |
showDumbModeNotification(java.lang.String message)
Show a notification when given action is not available during dumb mode.
|
abstract void |
smartInvokeLater(java.lang.Runnable runnable)
Invoke the runnable later on EventDispatchThread AND when IDE isn't in dumb mode.
|
abstract void |
smartInvokeLater(java.lang.Runnable runnable,
ModalityState modalityState)
Invoke the runnable later on EventDispatchThread with the given modality state AND when IDE isn't in dumb mode.
|
abstract void |
suspendIndexingAndRun(java.lang.String activityName,
java.lang.Runnable activity)
Runs a heavy activity and suspends indexing (if any) for this time.
|
<T> T |
tryRunReadActionInSmartMode(Computable<T> task,
java.lang.String notification) |
abstract void |
unsafeRunWhenSmart(java.lang.Runnable runnable) |
abstract void |
waitForSmartMode()
Pause the current thread until dumb mode ends and then continue execution.
|
void |
withAlternativeResolveEnabled(java.lang.Runnable runnable)
Invokes the given runnable with alternative resolve set to true.
|
abstract javax.swing.JComponent |
wrapGently(javax.swing.JComponent dumbUnawareContent,
Disposable parentDisposable)
Replaces given component temporarily with "Not available until indices are built" label during dumb mode.
|
abstract javax.swing.JComponent |
wrapWithSpoiler(javax.swing.JComponent dumbAwareContent,
java.lang.Runnable updateRunnable,
Disposable parentDisposable)
Adds a "Results might be incomplete while indexing." decorator to a given component during dumb mode.
|
public static final Topic<DumbService.DumbModeListener> DUMB_MODE
ComponentManager.getMessageBus()
public abstract ModificationTracker getModificationTracker()
public abstract boolean isDumb()
DumbService
public static boolean isDumb(Project project)
public static <T> java.util.List<T> getDumbAwareExtensions(Project project, ExtensionPointName<T> extensionPoint)
public static <T> java.util.List<T> getDumbAwareExtensions(Project project, ProjectExtensionPointName<T> extensionPoint)
public abstract void runWhenSmart(java.lang.Runnable runnable)
public abstract void waitForSmartMode()
runWhenSmart(Runnable)
or runReadActionInSmartMode(Runnable)
insteadpublic <T> T runReadActionInSmartMode(Computable<T> r)
ProcessCanceledException
- if the project is closed during dumb modepublic <T> T tryRunReadActionInSmartMode(Computable<T> task, java.lang.String notification)
public void runReadActionInSmartMode(java.lang.Runnable r)
ProcessCanceledException
- if the project is closed during dumb mode@Deprecated public void repeatUntilPassesInSmartMode(java.lang.Runnable r)
runReadActionInSmartMode(com.intellij.openapi.util.Computable<T>)
instead.public abstract void smartInvokeLater(java.lang.Runnable runnable)
public abstract void smartInvokeLater(java.lang.Runnable runnable, ModalityState modalityState)
public static DumbService getInstance(Project project)
public <T> java.util.List<T> filterByDumbAwareness(T [] array)
isDumb()
is true.isDumbAware(Object)
public <T> java.util.List<T> filterByDumbAwareness(java.util.Collection<? extends T> collection)
isDumb()
is true.isDumbAware(Object)
public abstract void queueTask(DumbModeTask task)
completeJustSubmittedTasks()
is called in the same dispatch thread activity.
Tasks can specify custom "equality" policy via their constructor. Calling this method has no effect if an "equal" task is already enqueued (but not yet running).
public abstract void cancelTask(DumbModeTask task)
ProgressIndicator
is canceled, so the next ProgressManager.checkCanceled()
call
will throw ProcessCanceledException
.public abstract void cancelAllTasksAndWait()
public abstract void completeJustSubmittedTasks()
This functionality can be useful in refactorings (invoked in "smart mode"), when after VFS or root changes (which could start "dumb mode") some reference resolve is required (which again requires "smart mode").
Should be invoked on dispatch thread. It's the caller's responsibility to invoke this method only when the model is in internally consistent state, so that background threads with read actions don't see half-baked PSI/VFS/etc.
public abstract javax.swing.JComponent wrapGently(javax.swing.JComponent dumbUnawareContent, Disposable parentDisposable)
public abstract javax.swing.JComponent wrapWithSpoiler(javax.swing.JComponent dumbAwareContent, java.lang.Runnable updateRunnable, Disposable parentDisposable)
dumbAwareContent
- - a component to wrapupdateRunnable
- - an action to execute when dumb mode state changed or user explicitly request reload panelpublic void makeDumbAware(javax.swing.JComponent componentToDisable, Disposable parentDisposable)
public abstract void showDumbModeNotification(java.lang.String message)
public abstract boolean showDumbModeDialog(java.util.List<java.lang.String> actionNames)
public abstract Project getProject()
public static boolean isDumbAware(java.lang.Object o)
@Deprecated public abstract void setAlternativeResolveEnabled(boolean enabled)
runWithAlternativeResolveEnabled(ThrowableRunnable)
or computeWithAlternativeResolveEnabled(ThrowableComputable)
or withAlternativeResolveEnabled(Runnable)
insteadNormally reference resolution uses indexes, and hence is not available in dumb mode. In some cases, alternative ways of performing resolve are available, although much slower. It's impractical to always use these ways because it'll lead to overloaded CPU (especially given there's also indexing in progress). But for some explicit user actions (e.g., explicit Goto Declaration) turning on these slower methods is beneficial.
NOTE: even with alternative resolution enabled, methods like resolve(), findClass() etc may still throw
IndexNotReadyException
. So alternative resolve is not a panacea, it might help provide navigation in some cases
but not in all.
A typical usage would involve try-finally
, where the alternative resolution is first enabled, then an action is performed,
and then alternative resolution is turned off in the finally
block.
public void withAlternativeResolveEnabled(java.lang.Runnable runnable)
setAlternativeResolveEnabled(boolean)
public <T,E extends java.lang.Throwable> T computeWithAlternativeResolveEnabled(ThrowableComputable<T,E> runnable) throws E extends java.lang.Throwable
E extends java.lang.Throwable
setAlternativeResolveEnabled(boolean)
public <E extends java.lang.Throwable> void runWithAlternativeResolveEnabled(ThrowableRunnable<E> runnable) throws E extends java.lang.Throwable
E extends java.lang.Throwable
setAlternativeResolveEnabled(boolean)
public abstract boolean isAlternativeResolveEnabled()
setAlternativeResolveEnabled(boolean)
@Deprecated public static void allowStartingDumbModeInside(DumbModePermission permission, java.lang.Runnable runnable)
completeJustSubmittedTasks()
public abstract void suspendIndexingAndRun(java.lang.String activityName, java.lang.Runnable activity)
activityName
- the text (a noun phrase) to display as a reason for the indexing being pausedpublic abstract boolean isSuspendedDumbMode()
isDumb()
is true for the current project and if it's currently suspended by user or a suspendIndexingAndRun(java.lang.String, java.lang.Runnable)
call.
This should be called inside read action. The momentary system state is returned: there are no guarantees that the result won't change
in the next line of the calling code.public abstract void unsafeRunWhenSmart(java.lang.Runnable runnable)