Skip to content
Snippets Groups Projects
Commit 612d6bf5 authored by Johannes Mey's avatar Johannes Mey
Browse files

do not refresh during path resolution while holding read lock

parent 221e6182
Branches
Tags
1 merge request!7Resolve "IDE Exception"
Pipeline #12025 passed
This commit is part of merge request !7. Comments created here will be created in the context of that merge request.
package org.jastadd.tooling.java;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.util.ui.EDT;
import org.jetbrains.annotations.NotNull;
import java.nio.file.Paths;
......@@ -33,8 +36,11 @@ public class GeneratedCodeUtil {
}
String path = jastAddFileLocation.substring(0, pos);
System.out.println(path);
VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
// the method performing the refresh is not allowed when the following condition is not met
// see com.intellij.openapi.vfs.newvfs.RefreshQueueImpl:execute
VirtualFile vFile = ((ApplicationEx) ApplicationManager.getApplication()).holdsReadLock() || EDT.isCurrentThreadEdt()
? LocalFileSystem.getInstance().findFileByPath(path)
: LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
int line;
try {
......@@ -45,7 +51,6 @@ public class GeneratedCodeUtil {
if (vFile == null) {
return Paths.get(path).getFileName() + (line == 0 ? "" : ":" + line);
}
System.out.println(line);
Document document = FileDocumentManager.getInstance().getDocument(vFile);
if (document == null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment