Aalto-LeTech / aplus-courses

A+ Courses is a plugin for IntelliJ IDEA, used in programming courses at Aalto University
https://plugins.jetbrains.com/plugin/13634-a-courses
MIT License
17 stars 7 forks source link

Make Actions "DumbAware" when possible #129

Closed OlliKiljunen closed 4 years ago

OlliKiljunen commented 4 years ago

Implementing DumbAware makes the action available during indexing (that long process that happens when you start the IDE). As long as the action doesn't access the indices, it can/should implement DumbAware. The problem is that I'm not 100% sure which methods from the API need the indices and which don't, but the good news is that an exception is thrown if the indices are accessed before they are ready :smile:

Originally posted by @nikke234 in https://github.com/Aalto-LeTech/intellij-plugin/pull/126

One should go through our action classes (some others too?), study which of them could/should be "DumbAware" and change the code accordingly.

nikke234 commented 4 years ago

More information from a comment in the source code of IDEA's API (DumbService.java):

 * A service managing the IDE's 'dumb' mode: when indexes are updated in the background, and the functionality is very much limited.
 * Only the explicitly allowed functionality is available. Usually, it's allowed by implementing {@link DumbAware} interface.<p></p>
 * <p>
 * "Dumb" mode starts and ends in a {@link com.intellij.openapi.application.WriteAction}, so if you're inside a {@link 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 {@link #runReadActionInSmartMode} or
 * {@link com.intellij.openapi.application.NonBlockingReadAction#inSmartMode}.
 * <p>
nikke234 commented 4 years ago

...and from IndexNotReadyException.java:

 * Thrown on accessing indices in dumb mode. Possible fixes:
 * <li> if {@link com.intellij.openapi.actionSystem.AnAction#actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent)} is in stack trace,
 * consider making the action not implement {@link com.intellij.openapi.project.DumbAware}.
 * <li> if this access is performed from some invokeLater activity, consider replacing it with
 * {@link com.intellij.openapi.project.DumbService#smartInvokeLater(Runnable)}
 * <li> otherwise, add {@link DumbService#isDumb()} checks where necessary
nikke234 commented 4 years ago

I suspect ImportProjectSettingsAction could be dumb aware since it only copies files in to the .idea directory and reloads the project

superseacat commented 4 years ago

check "Import A+ Module" especially, as this would increase the installation speed of multi-module projects

superseacat commented 4 years ago

well, why not... ReplAction.scala ?

superseacat commented 4 years ago

and Activity's too :stuck_out_tongue_winking_eye: