Skip to content

Commit

Permalink
Handle client cancellation without reporting an error
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenporras committed Apr 6, 2023
1 parent ca0c636 commit 00e62a6
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.net.URI;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
Expand Down Expand Up @@ -255,23 +256,25 @@ private void fullReconcile() {
long modificationStamp = DocumentUtil.getDocumentModificationStamp(theDocument);
LanguageServerDocumentExecutor executor = LanguageServers.forDocument(theDocument)
.withFilter(this::hasSemanticTokensFull);
semanticTokensFullFuture = executor//
try {
semanticTokensFullFuture = executor//
.computeFirst((w, ls) -> ls.getTextDocumentService().semanticTokensFull(getSemanticTokensParams())//
.thenApply(semanticTokens -> new VersionedSemanticTokens(modificationStamp,
Pair.of(semanticTokens, getSemanticTokensLegend(w)), theDocument)));

try {
semanticTokensFullFuture.get() // background thread with cancellation support, no timeout needed
.ifPresent(versionedSemanticTokens -> {
versionedSemanticTokens.apply(this::saveStyle, this::invalidateTextPresentation);
});
} catch (ResponseErrorException | ExecutionException e) {
if (!CancellationUtil.isRequestCancelledException(e)) {
if (!CancellationUtil.isRequestCancelledException(e)) { // do not report error if the server has cancelled the request
LanguageServerPlugin.logError(e);
}
} catch (InterruptedException e) {
LanguageServerPlugin.logError(e);
Thread.currentThread().interrupt();
} catch (CancellationException e) {
// nothing to do, the client has cancelled the request because the document has been closed or a new request has been sent
}
}
}
Expand Down

0 comments on commit 00e62a6

Please sign in to comment.