fix: Some more null/safety checks

This commit is contained in:
FalsePattern 2023-08-17 18:26:48 +02:00
parent cfb4abbe93
commit 7b4067aca4
Signed by: falsepattern
GPG key ID: FDF7126A9E124447
3 changed files with 9 additions and 2 deletions

View file

@ -156,7 +156,9 @@ public class LSPFoldingRangeProvider extends CustomFoldingBuilder {
try {
List<FoldingRange> foldingRanges = future.get(Timeout.getTimeout(Timeouts.FOLDING), TimeUnit.MILLISECONDS);
wrapper.notifySuccess(Timeouts.FOLDING);
if (foldingRanges == null) {
return;
}
for (FoldingRange foldingRange : foldingRanges) {
int start = getStartOffset(editor, foldingRange, document);
int end = getEndOffset(editor, foldingRange, document);

View file

@ -339,6 +339,9 @@ public class EditorEventManager {
Either<List<? extends Location>, List<? extends LocationLink>> definition =
request.get(Timeout.getTimeout(Timeouts.DEFINITION), TimeUnit.MILLISECONDS);
wrapper.notifySuccess(Timeouts.DEFINITION);
if (definition == null) {
return null;
}
if (definition.isLeft() && !definition.getLeft().isEmpty()) {
return definition.getLeft().get(0);
} else if (definition.isRight() && !definition.getRight().isEmpty()) {

View file

@ -16,6 +16,7 @@
package com.falsepattern.zigbrains.lsp.utils;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.project.NoAccessDuringPsiEvents;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Condition;
@ -51,7 +52,8 @@ public class ApplicationUtils {
}
static public <T> T computableReadAction(Computable<T> computable) {
if (ApplicationManager.getApplication().isDispatchThread()) {
if (ApplicationManager.getApplication().isDispatchThread() ||
ApplicationManagerEx.getApplicationEx().holdsReadLock()) {
return ApplicationManager.getApplication().runReadAction(computable);
} else {
var result = new Object() {