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 c34190b93..e64e57cfc 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 @@ -82,8 +82,12 @@ public void computeDiagnostics(String camelText, TextDocumentItem documentItem) diagnostics.addAll(camelKModelineDiagnosticService.compute(camelText, documentItem)); diagnostics.addAll(camelKafkaConnectorDiagnosticService.compute(camelText, documentItem)); diagnostics.addAll(connectedModeDiagnosticService.compute(camelText, documentItem)); - camelLanguageServer.getClient().publishDiagnostics(new PublishDiagnosticsParams(uri, diagnostics)); - lastTriggeredDiagnostic.remove(uri); + if(!Thread.currentThread().isInterrupted()) { + camelLanguageServer.getClient().publishDiagnostics(new PublishDiagnosticsParams(uri, diagnostics)); + lastTriggeredDiagnostic.remove(uri); + } else { + System.out.println("### Thread was interrupted (i.e. Future for diagnostic cancelled)"); + } }); lastTriggeredDiagnostic.put(uri, lastTriggeredComputation); } @@ -100,6 +104,7 @@ public void clear(String uri) { CompletableFuture previousComputation = lastTriggeredDiagnostic.get(uri); if (previousComputation != null) { previousComputation.cancel(true); + lastTriggeredDiagnostic.remove(uri); } camelLanguageServer.getClient().publishDiagnostics(new PublishDiagnosticsParams(uri, Collections.emptyList())); } diff --git a/src/test/java/com/github/cameltooling/lsp/internal/AbstractCamelLanguageServerTest.java b/src/test/java/com/github/cameltooling/lsp/internal/AbstractCamelLanguageServerTest.java index bc1faad31..d2e7c9678 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/AbstractCamelLanguageServerTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/AbstractCamelLanguageServerTest.java @@ -136,6 +136,7 @@ public void showMessage(MessageParams messageParams) { @Override public void publishDiagnostics(PublishDiagnosticsParams diagnostics) { + System.out.println("Published Diagnostics " + diagnostics.getUri() +" "+ diagnostics.getDiagnostics().size()); AbstractCamelLanguageServerTest.this.lastPublishedDiagnostics = diagnostics; } diff --git a/src/test/java/com/github/cameltooling/lsp/internal/diagnostic/CamelDiagnosticTest.java b/src/test/java/com/github/cameltooling/lsp/internal/diagnostic/CamelDiagnosticTest.java index 32545315d..499f4e7fd 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/diagnostic/CamelDiagnosticTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/diagnostic/CamelDiagnosticTest.java @@ -142,16 +142,22 @@ void testNoExceptionOnInvalidJavaFile() throws Exception { @Test void testValidationErrorClearedOnClose() throws Exception { + System.out.println("### Starting testValidationErrorClearedOnClose test "); testDiagnostic("camel-with-endpoint-error", 1, ".xml"); + System.out.println("### Will close"); + DidCloseTextDocumentParams params = new DidCloseTextDocumentParams(new TextDocumentIdentifier(DUMMY_URI+".xml")); camelLanguageServer.getTextDocumentService().didClose(params); + System.out.println("### didClose sent"); + await().timeout(AWAIT_TIMEOUT.multipliedBy(2)).untilAsserted(() -> assertThat(lastPublishedDiagnostics.getDiagnostics()).isEmpty()); } @Test void testValidationErrorUpdatedOnChange() throws Exception { + System.out.println("### Starting testValidationErrorUpdatedOnChange test "); testDiagnostic("camel-with-endpoint-error", 1, ".xml"); camelLanguageServer.getTextDocumentService().getOpenedDocument(DUMMY_URI+".xml").getText();