1212
1313import com .intellij .find .findUsages .CustomUsageSearcher ;
1414import com .intellij .find .findUsages .FindUsagesOptions ;
15+ import com .intellij .openapi .application .ApplicationManager ;
1516import com .intellij .openapi .application .ReadAction ;
1617import com .intellij .openapi .editor .Document ;
1718import com .intellij .psi .PsiElement ;
@@ -62,7 +63,7 @@ public void processElementUsages(@NotNull PsiElement element, @NotNull Processor
6263 }
6364 }
6465
65- // Get position where the "Find USages " has been triggered
66+ // Get position where the "Find Usages " has been triggered
6667 Position position = getPosition (element );
6768 // Collect textDocument/definition, textDocument/references, etc
6869 LSPUsageSupport usageSupport = new LSPUsageSupport (element .getContainingFile ());
@@ -85,7 +86,14 @@ public void processElementUsages(@NotNull PsiElement element, @NotNull Processor
8586 }
8687 }
8788
88- private Position getPosition (PsiElement element ) {
89+ private static Position getPosition (PsiElement element ) {
90+ if (ApplicationManager .getApplication ().isReadAccessAllowed ()) {
91+ return doGetPosition (element );
92+ }
93+ return ReadAction .compute (() -> doGetPosition (element ));
94+ }
95+
96+ private static Position doGetPosition (PsiElement element ) {
8997 Document document = LSPIJUtils .getDocument (element .getContainingFile ().getVirtualFile ());
9098 return LSPIJUtils .toPosition (Math .min (element .getTextRange ().getStartOffset () + 1 , element .getTextRange ().getEndOffset ()), document );
9199 }
0 commit comments