Skip to content

Commit 844a9d6

Browse files
committed
EyeTracker: wrap call to getASTStructureElement() in runReadAction()
This should fix the sporadic RuntimeExceptionWithAttachments exception in CodeGRITS plugin that happens on some projects when running eye tracker. com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: Read access is allowed from inside read-action only (see Application.runReadAction()); If you access or modify model on EDT consider wrapping your code in WriteIntentReadAction ; see https://jb.gg/ij-platform-threading for details [...] at trackers.EyeTracker.getASTStructureElement(EyeTracker.java:450) at trackers.EyeTracker.lambda$processRawData$1(EyeTracker.java:306) This fix is based on the https://stackoverflow.com/q/76809649 and the discussion in issue #17 .
1 parent 5a28ae1 commit 844a9d6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/java/trackers/EyeTracker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
1010
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
1111
import com.intellij.openapi.project.Project;
12+
import com.intellij.openapi.util.Computable;
1213
import com.intellij.openapi.vfs.VirtualFile;
1314
import com.intellij.psi.PsiDocumentManager;
1415
import com.intellij.psi.PsiElement;
@@ -250,7 +251,9 @@ public void processRawData(String message) {
250251
location.setAttribute("column", String.valueOf(logicalPosition.column));
251252
location.setAttribute("path", RelativePathGetter.getRelativePath(filePath, projectPath));
252253
gaze.appendChild(location);
253-
Element aSTStructure = getASTStructureElement(psiElement);
254+
Element aSTStructure = ApplicationManager.getApplication().runReadAction(
255+
(Computable<Element>) () -> getASTStructureElement(psiElement)
256+
);
254257
gaze.appendChild(aSTStructure);
255258
lastElement = psiElement;
256259
// System.out.println(gaze.getAttribute("timestamp") + " " + System.currentTimeMillis());

0 commit comments

Comments
 (0)