-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ResponseErrorException when Ctrl+Hover due to cancellation
Fixes #1136 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
3fbeb41
commit 5c13e1c
Showing
3 changed files
with
80 additions
and
31 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/com/redhat/devtools/intellij/lsp4ij/internal/CancellationUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Avaloq Group AG. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Rubén Porras Campo (Avaloq Group AG) - Initial Implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4ij.internal; | ||
|
||
import java.util.concurrent.CancellationException; | ||
import java.util.concurrent.CompletionException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException; | ||
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError; | ||
import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode; | ||
|
||
public final class CancellationUtil { | ||
|
||
private CancellationUtil() { | ||
// this class shouldn't be instantiated | ||
} | ||
|
||
public static boolean isRequestCancelledException(Throwable throwable) { | ||
if (throwable instanceof CompletionException | throwable instanceof ExecutionException) { | ||
throwable = throwable.getCause(); | ||
} | ||
if (throwable instanceof ResponseErrorException) { | ||
return isRequestCancelled((ResponseErrorException)throwable); | ||
} | ||
return throwable instanceof CancellationException; | ||
} | ||
|
||
private static boolean isRequestCancelled(ResponseErrorException responseErrorException) { | ||
ResponseError responseError = responseErrorException.getResponseError(); | ||
return responseError != null | ||
&& responseError.getCode() == ResponseErrorCode.RequestCancelled.getValue(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters