Skip to content

Commit 162897a

Browse files
authored
Merge pull request #19 from mrglavas/q0401
fix: Find usages on a Java file can generate many IDE internal errors.
2 parents 3697ad7 + 7ecbaa7 commit 162897a

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/main/java/org/microshed/lsp4ij/usages/LSPUsageSearcher.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.intellij.find.findUsages.CustomUsageSearcher;
1414
import com.intellij.find.findUsages.FindUsagesOptions;
15+
import com.intellij.openapi.application.ApplicationManager;
1516
import com.intellij.openapi.application.ReadAction;
1617
import com.intellij.openapi.editor.Document;
1718
import 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

Comments
 (0)