Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle client cancellation without reporting an error #603

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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