Skip to content

Commit d21cff9

Browse files
committed
fix: Read access is allowed from inside read-action only in
LSPUsageSearcher Fixes #1605 Signed-off-by: azerr <azerr@redhat.com>
1 parent 12149cb commit d21cff9

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

src/main/java/com/redhat/devtools/lsp4ij/usages/LSPUsageSearcher.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ public class LSPUsageSearcher extends CustomUsageSearcher {
7777

7878
private static final Logger LOGGER = LoggerFactory.getLogger(LSPUsageSearcher.class);
7979

80-
record ElementContext(Project project, Position position, PsiFile file) {
81-
}
82-
8380
/**
8481
* Processes all usages of the given element by querying the language server.
8582
* <p>
@@ -113,17 +110,26 @@ record ElementContext(Project project, Position position, PsiFile file) {
113110
@Override
114111
public void processElementUsages(@NotNull PsiElement element, @NotNull Processor<? super Usage> processor, @NotNull FindUsagesOptions options) {
115112
// 1. Collect only what we need from the element inside a narrow ReadAction
116-
ElementContext ctx = runCancellableReadAction(() -> {
113+
record ElementData(Project project, Position position, PsiFile file, int textOffset) {}
114+
ElementData data = runCancellableReadAction(() -> {
117115
PsiFile file = element.getContainingFile();
118-
return new ElementContext(file.getProject(), getPosition(element, file), file);
116+
if (file == null) {
117+
return null;
118+
}
119+
Position position = getPosition(element, file);
120+
if (position == null) {
121+
return null;
122+
}
123+
return new ElementData(element.getProject(), position, file, element.getTextOffset());
119124
}, ApplicationManager.getApplication());
120-
Project project = ctx.project();
121-
Position position = ctx.position();
122-
PsiFile file = ctx.file();
123-
124-
if (position == null || file == null) {
125+
126+
if (data == null) {
125127
return;
126128
}
129+
130+
Project project = data.project();
131+
PsiFile file = data.file();
132+
Position position = data.position();
127133
if (!isUsageSupportedByLanguageServer(file)) {
128134
return;
129135
}
@@ -200,7 +206,7 @@ public void processElementUsages(@NotNull PsiElement element, @NotNull Processor
200206

201207
LSPExternalReferencesFinder.processExternalReferences(
202208
file,
203-
element.getTextOffset(),
209+
data.textOffset(),
204210
searchScope,
205211
reference -> processor.process(new UsageInfo2UsageAdapter(new UsageInfo(reference)))
206212
);

0 commit comments

Comments
 (0)