Skip to content

Commit b2e00d5

Browse files
committed
FUSETOOLS2-1505 - avoid flakiness in case of concurrent of Diagnostics
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 <[email protected]>
1 parent 2cfe4f9 commit b2e00d5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/com/github/cameltooling/lsp/internal/diagnostic/DiagnosticRunner.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.HashMap;
1515
import java.util.List;
1616
import java.util.Map;
17+
import java.util.concurrent.CancellationException;
1718
import java.util.concurrent.CompletableFuture;
1819

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

4546
public DiagnosticRunner(CompletableFuture<CamelCatalog> camelCatalog, CamelLanguageServer camelLanguageServer) {
4647
this.camelLanguageServer = camelLanguageServer;
@@ -99,7 +100,11 @@ private String retrieveFullText(DidSaveTextDocumentParams params) {
99100
public void clear(String uri) {
100101
CompletableFuture<Void> previousComputation = lastTriggeredDiagnostic.get(uri);
101102
if (previousComputation != null) {
102-
previousComputation.cancel(true);
103+
try {
104+
previousComputation.cancel(true);
105+
} catch (CancellationException ce) {
106+
// Do nothing
107+
}
103108
}
104109
camelLanguageServer.getClient().publishDiagnostics(new PublishDiagnosticsParams(uri, Collections.emptyList()));
105110
}

0 commit comments

Comments
 (0)