Skip to content

Commit 772e1f0

Browse files
committed
fix: move PsiFile retrieval and context check under read actions
1 parent 029f2a7 commit 772e1f0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main/java/com/github/lppedd/cc/angular2/Angular2CommitScopeProvider.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import com.intellij.openapi.project.Project;
1818
import com.intellij.openapi.util.Computable;
1919
import com.intellij.openapi.vfs.VirtualFile;
20+
import com.intellij.psi.PsiElement;
21+
import com.intellij.psi.PsiFile;
2022
import com.intellij.psi.PsiFileSystemItem;
2123
import com.intellij.psi.search.FilenameIndex;
2224
import com.intellij.psi.search.GlobalSearchScope;
@@ -93,8 +95,8 @@ private List<CommitScope> findNgModules() {
9395
)
9496
).stream()
9597
)
96-
.map(virtualFile -> PsiUtilCore.getPsiFile(project, virtualFile))
97-
.filter(Angular2LangUtil::isAngular2Context)
98+
.map(this::toPsiFile)
99+
.filter(this::isAngular2Context)
98100
.map(PsiFileSystemItem::getName)
99101
.map(String::toLowerCase)
100102
.map(fileName -> fileName.replaceFirst(".module.ts$", ""))
@@ -103,6 +105,18 @@ private List<CommitScope> findNgModules() {
103105
.collect(Collectors.toList());
104106
}
105107

108+
private PsiFile toPsiFile(final VirtualFile virtualFile) {
109+
return APPLICATION.runReadAction(
110+
(Computable<PsiFile>) () -> PsiUtilCore.getPsiFile(project, virtualFile)
111+
);
112+
}
113+
114+
private boolean isAngular2Context(final PsiElement psiFile) {
115+
return APPLICATION.runReadAction(
116+
(Computable<Boolean>) () -> Angular2LangUtil.isAngular2Context(psiFile)
117+
);
118+
}
119+
106120
private static class Angular2CommitBuildScope extends CommitScope {
107121
Angular2CommitBuildScope(
108122
@NotNull final String text,

0 commit comments

Comments
 (0)