Skip to content

Commit

Permalink
fix: Deadlock with IDEA EAP 2023-3 EAP
Browse files Browse the repository at this point in the history
Fixes #1192

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 4, 2023
1 parent abf9c7d commit 2f3ea4c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void bind(CancellablePromise<ResultOrError<R>> promise) {
promise.onError(ex -> {
if (ex instanceof ProcessCanceledException || ex instanceof CancellationException) {
// Case 2: cancel the completable future
this.cancel(true);
super.cancel(true);
} else {
// Other case..., mark the completable future as error
this.completeExceptionally(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,33 @@ public boolean collect(@NotNull PsiElement psiElement, @NotNull Editor editor, @
// The project has been closed, don't collect code lenses.
return false;
}
VirtualFile file = LSPIJUtils.getFile(psiFile);
if (file == null) {
return false;
}
URI fileUri = LSPIJUtils.toUri(file);
if (fileUri == null) {
return false;
}
Document document = editor.getDocument();
final CancellationSupport cancellationSupport = new CancellationSupport();
try {
VirtualFile file = LSPIJUtils.getFile(psiElement);
URI docURI = LSPIJUtils.toUri(file);
if (docURI != null) {
CodeLensParams param = new CodeLensParams(new TextDocumentIdentifier(docURI.toString()));
BlockingDeque<Pair<CodeLens, LanguageServer>> pairs = new LinkedBlockingDeque<>();

CompletableFuture<Void> future = collect(file, project, param, pairs, cancellationSupport);
List<Pair<Integer, Pair<CodeLens, LanguageServer>>> codeLenses = createCodeLenses(document, pairs, future, cancellationSupport);
codeLenses.stream()
.collect(Collectors.groupingBy(p -> p.first))
.forEach((offset, list) ->
inlayHintsSink.addBlockElement(
offset,
true,
true,
0,
toPresentation(editor, offset, list, getFactory()))
);
}
CodeLensParams param = new CodeLensParams(new TextDocumentIdentifier(fileUri.toString()));
BlockingDeque<Pair<CodeLens, LanguageServer>> pairs = new LinkedBlockingDeque<>();

CompletableFuture<Void> future = collect(file, project, param, pairs, cancellationSupport);
List<Pair<Integer, Pair<CodeLens, LanguageServer>>> codeLenses = createCodeLenses(document, pairs, future, cancellationSupport);
codeLenses.stream()
.collect(Collectors.groupingBy(p -> p.first))
.forEach((offset, list) ->
inlayHintsSink.addBlockElement(
offset,
true,
true,
0,
toPresentation(editor, offset, list, getFactory()))
);
} catch (ProcessCanceledException e) {
// Cancel all LSP requests
cancellationSupport.cancel();
Expand All @@ -109,16 +114,11 @@ public boolean collect(@NotNull PsiElement psiElement, @NotNull Editor editor, @
private List<Pair<Integer, Pair<CodeLens, LanguageServer>>> createCodeLenses(Document document, BlockingDeque<Pair<CodeLens, LanguageServer>> pairs, CompletableFuture<Void> future, CancellationSupport cancellationSupport) throws InterruptedException {
List<Pair<Integer, Pair<CodeLens, LanguageServer>>> codelenses = new ArrayList<>();
while (!future.isDone() || !pairs.isEmpty()) {
try {
ProgressManager.checkCanceled();
Pair<CodeLens, LanguageServer> pair = pairs.poll(25, TimeUnit.MILLISECONDS);
if (pair != null) {
int offset = LSPIJUtils.toOffset(pair.getFirst().getRange().getStart(), document);
codelenses.add(Pair.create(offset, pair));
}
} catch (ProcessCanceledException e) {
cancellationSupport.cancel();
throw e;
ProgressManager.checkCanceled();
Pair<CodeLens, LanguageServer> pair = pairs.poll(25, TimeUnit.MILLISECONDS);
if (pair != null) {
int offset = LSPIJUtils.toOffset(pair.getFirst().getRange().getStart(), document);
codelenses.add(Pair.create(offset, pair));
}
}
return codelenses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ public boolean collect(@NotNull PsiElement psiElement, @NotNull Editor editor, @
// The project has been closed, don't collect inlay hints.
return false;
}
VirtualFile file = LSPIJUtils.getFile(psiFile);
if (file == null) {
return false;
}
URI fileUri = LSPIJUtils.toUri(file);
if (fileUri == null) {
return false;
}
Document document = editor.getDocument();
final CancellationSupport cancellationSupport = new CancellationSupport();
try {
VirtualFile file = LSPIJUtils.getFile(psiFile);
if (file == null) {
return false;
}
URI docURI = LSPIJUtils.toUri(file);
Range viewPortRange = getViewPortRange(editor);
InlayHintParams param = new InlayHintParams(new TextDocumentIdentifier(docURI.toString()), viewPortRange);
InlayHintParams param = new InlayHintParams(new TextDocumentIdentifier(fileUri.toASCIIString()), viewPortRange);
BlockingDeque<Pair<InlayHint, LanguageServer>> pairs = new LinkedBlockingDeque<>();

CompletableFuture<Void> future = collect(psiElement.getProject(), file, param, pairs, cancellationSupport);
Expand All @@ -90,7 +93,7 @@ public boolean collect(@NotNull PsiElement psiElement, @NotNull Editor editor, @
} catch (ProcessCanceledException e) {
// Cancel all LSP requests
cancellationSupport.cancel();
throw e;
return false; //throw e;
} catch (InterruptedException e) {
LOGGER.warn(e.getLocalizedMessage(), e);
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.intellij.lsp4ij.operations.codelens.LSPCodelensInlayProvider;
import com.redhat.devtools.intellij.lsp4mp4ij.settings.MicroProfileInspectionsInfo;
import com.redhat.devtools.intellij.quarkus.TelemetryService;
import com.redhat.devtools.intellij.lsp4ij.server.JavaProcessCommandBuilder;
import com.redhat.devtools.intellij.lsp4ij.server.ProcessStreamConnectionProvider;
import com.redhat.devtools.intellij.lsp4mp4ij.settings.UserDefinedMicroProfileSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URI;
Expand All @@ -32,6 +35,8 @@
*/
public class QuarkusServer extends ProcessStreamConnectionProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(QuarkusServer.class);

private final Project project;

public QuarkusServer(Project project) {
Expand All @@ -47,7 +52,12 @@ public QuarkusServer(Project project) {
commands.add("-DrunAsync=true");
super.setCommands(commands);

TelemetryService.instance().action(TelemetryService.LSP_PREFIX + "start").send();
try {
TelemetryService.instance().action(TelemetryService.LSP_PREFIX + "start").send();
}
catch(Exception e) {
LOGGER.error("Error while consuming telemtry service", e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import com.redhat.devtools.intellij.quarkus.TelemetryService;
import com.redhat.devtools.intellij.lsp4ij.server.JavaProcessCommandBuilder;
import com.redhat.devtools.intellij.lsp4ij.server.ProcessStreamConnectionProvider;
import com.redhat.devtools.intellij.quarkus.lsp.QuarkusServer;
import com.redhat.devtools.intellij.qute.settings.QuteInspectionsInfo;
import com.redhat.devtools.intellij.qute.settings.UserDefinedQuteSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URI;
Expand All @@ -33,6 +36,8 @@
*/
public class QuteServer extends ProcessStreamConnectionProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(QuteServer.class);

private final Project project;

public QuteServer(Project project) {
Expand All @@ -46,7 +51,12 @@ public QuteServer(Project project) {
commands.add("-DrunAsync=true");
super.setCommands(commands);

TelemetryService.instance().action(TelemetryService.LSP_PREFIX + "startQute").send();
try {
TelemetryService.instance().action(TelemetryService.LSP_PREFIX + "startQute").send();
}
catch(Exception e) {
LOGGER.error("Error while consuming telemtry service", e);
}
}

@Override
Expand Down

0 comments on commit 2f3ea4c

Please sign in to comment.