Skip to content

Commit

Permalink
FUSETOOLS2-1505 - avoid flakiness in case of concurrent of Diagnostics
Browse files Browse the repository at this point in the history
I previously missed the part that there was an Exception thrown in case
the cancel was useful...

```If not already completed, completes this CompletableFuture with a
CancellationException.```

Signed-off-by: Aurélien Pupier <apupier@redhat.com>
  • Loading branch information
apupier committed Jun 5, 2023
1 parent 2cfe4f9 commit b2e00d5
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;

import org.apache.camel.catalog.CamelCatalog;
Expand All @@ -40,7 +41,7 @@ public class DiagnosticRunner {
private CamelKModelineDiagnosticService camelKModelineDiagnosticService;
private CamelKafkaConnectorDiagnosticService camelKafkaConnectorDiagnosticService;
private ConnectedModeDiagnosticService connectedModeDiagnosticService;
private Map<String, CompletableFuture<Void>> lastTriggeredDiagnostic = new HashMap<String, CompletableFuture<Void>>();
private Map<String, CompletableFuture<Void>> lastTriggeredDiagnostic = new HashMap<>();

public DiagnosticRunner(CompletableFuture<CamelCatalog> camelCatalog, CamelLanguageServer camelLanguageServer) {
this.camelLanguageServer = camelLanguageServer;
Expand Down Expand Up @@ -99,7 +100,11 @@ private String retrieveFullText(DidSaveTextDocumentParams params) {
public void clear(String uri) {
CompletableFuture<Void> previousComputation = lastTriggeredDiagnostic.get(uri);
if (previousComputation != null) {
previousComputation.cancel(true);
try {
previousComputation.cancel(true);
} catch (CancellationException ce) {
// Do nothing
}
}
camelLanguageServer.getClient().publishDiagnostics(new PublishDiagnosticsParams(uri, Collections.emptyList()));
}
Expand Down

0 comments on commit b2e00d5

Please sign in to comment.