Skip to content

Commit

Permalink
fix read-lock asserts in PsiViewerTreeModel
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmedvedev authored and hurricup committed Dec 22, 2023
1 parent 5638775 commit f2e3a0d
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package idea.plugin.psiviewer.model;

import com.intellij.openapi.application.ReadAction;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import idea.plugin.psiviewer.controller.project.PsiViewerProjectService;
Expand Down Expand Up @@ -69,14 +70,16 @@ public boolean isLeaf(Object node) {
}

private List<PsiElement> getFilteredChildren(PsiElement psi) {
final List<PsiElement> filteredChildren = new ArrayList<>();
return ReadAction.compute(() -> {
final List<PsiElement> filteredChildren = new ArrayList<>();

for (PsiElement e = psi.getFirstChild(); e != null; e = e.getNextSibling())
if (isValid(e)) {
filteredChildren.add(e);
}
for (PsiElement e = psi.getFirstChild(); e != null; e = e.getNextSibling())
if (isValid(e)) {
filteredChildren.add(e);
}

return filteredChildren;
return filteredChildren;
});
}

private boolean isValid(PsiElement psiElement) {
Expand Down

0 comments on commit f2e3a0d

Please # to comment.