Skip to content

Commit

Permalink
#493 It's prohibited to access index during event dispatching
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz committed Nov 17, 2017
1 parent 61f3a2c commit 3342dbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://www.jetbrains.com/intellij-repository/releases
# https://www.jetbrains.com/intellij-repository/snapshots

ideaVersion = 2017.1.5
ideaVersion = 2016.3.7
ideaType = IC
javaVersion = 1.6
javaTargetVersion = 1.6
Expand All @@ -23,4 +23,4 @@ publishChannel =
org.gradle.jvmargs=-XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=utf-8
JDK6_HOME=/usr/lib/jvm/java-6-jdk/

idePath =
idePath = /home/hsz/IDE/idea-IU-171.4694.70
25 changes: 15 additions & 10 deletions src/mobi/hsz/idea/gitignore/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import com.intellij.ide.plugins.IdeaPluginDescriptorImpl;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
Expand All @@ -48,15 +46,12 @@
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.messages.MessageBus;
import mobi.hsz.idea.gitignore.IgnoreBundle;
import mobi.hsz.idea.gitignore.command.CreateFileCommandAction;
import mobi.hsz.idea.gitignore.file.type.IgnoreFileType;
Expand All @@ -66,6 +61,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.InvocationTargetException;
import java.util.*;

import static com.intellij.ui.SimpleTextAttributes.REGULAR_ATTRIBUTES;
Expand Down Expand Up @@ -548,10 +544,19 @@ public static void addColoredText(@NotNull PresentationData data, @NotNull Strin
* @return event is processed
*/
public static boolean isInsideEventProcessing() {
Application application = ApplicationManager.getApplication();
if (!application.isWriteAccessAllowed()) return false;

MessageBus bus = application.getMessageBus();
return bus.hasUndeliveredEvents(VirtualFileManager.VFS_CHANGES) || bus.hasUndeliveredEvents(PsiModificationTracker.TOPIC);
try {
return (Boolean) Class
.forName("com.intellij.openapi.project.NoAccessDuringPsiEvents")
.getMethod("isInsideEventProcessing")
.invoke(null);
} catch (ClassNotFoundException e) {
return false;
} catch (NoSuchMethodException e) {
return false;
} catch (IllegalAccessException e) {
return false;
} catch (InvocationTargetException e) {
return false;
}
}
}

0 comments on commit 3342dbf

Please sign in to comment.