From cff2ebce014e029e9bc606e31215aad272e4e6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pupier?= Date: Mon, 5 Jun 2023 16:02:51 +0200 Subject: [PATCH] FUSETOOLS2-1505 - avoid flakiness in case of concurrent of Diagnostics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../lsp/internal/diagnostic/DiagnosticRunner.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/cameltooling/lsp/internal/diagnostic/DiagnosticRunner.java b/src/main/java/com/github/cameltooling/lsp/internal/diagnostic/DiagnosticRunner.java index f1ee537a..1831d95e 100644 --- a/src/main/java/com/github/cameltooling/lsp/internal/diagnostic/DiagnosticRunner.java +++ b/src/main/java/com/github/cameltooling/lsp/internal/diagnostic/DiagnosticRunner.java @@ -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; @@ -39,7 +40,7 @@ public class DiagnosticRunner { private ConfigurationPropertiesDiagnosticService configurationPropertiesDiagnosticService; private CamelKModelineDiagnosticService camelKModelineDiagnosticService; private ConnectedModeDiagnosticService connectedModeDiagnosticService; - private Map> lastTriggeredDiagnostic = new HashMap>(); + private Map> lastTriggeredDiagnostic = new HashMap<>(); public DiagnosticRunner(CompletableFuture camelCatalog, CamelLanguageServer camelLanguageServer) { this.camelLanguageServer = camelLanguageServer; @@ -96,7 +97,11 @@ private String retrieveFullText(DidSaveTextDocumentParams params) { public void clear(String uri) { CompletableFuture 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())); }