File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed
main/java/com/github/_1c_syntax/bsl/languageserver
test/java/com/github/_1c_syntax/bsl/languageserver Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 104104import org .eclipse .lsp4j .TextDocumentContentChangeEvent ;
105105import org .eclipse .lsp4j .TextEdit ;
106106import org .eclipse .lsp4j .WorkspaceEdit ;
107+ import org .eclipse .lsp4j .jsonrpc .CompletableFutures ;
107108import org .eclipse .lsp4j .jsonrpc .messages .Either ;
108109import org .eclipse .lsp4j .jsonrpc .messages .Either3 ;
109110import org .eclipse .lsp4j .services .TextDocumentService ;
@@ -755,9 +756,14 @@ private void processDocumentChange(
755756 waitFuture = CompletableFuture .completedFuture (null );
756757 }
757758
758- return waitFuture .thenApplyAsync (
759- ignored -> supplier .get (),
760- executorService
759+ return waitFuture .thenCompose (ignored ->
760+ CompletableFutures .computeAsync (
761+ executorService ,
762+ cancelChecker -> {
763+ cancelChecker .checkCanceled ();
764+ return supplier .get ();
765+ }
766+ )
761767 );
762768 }
763769}
Original file line number Diff line number Diff line change @@ -289,6 +289,32 @@ void testRenamePrepare() {
289289 assertThat (result ).isNotNull ();
290290 }
291291
292+ @ Test
293+ void testCancellationSupport () throws IOException {
294+ // given
295+ var textDocumentItem = getTextDocumentItem ();
296+ var didOpenParams = new DidOpenTextDocumentParams (textDocumentItem );
297+ textDocumentService .didOpen (didOpenParams );
298+
299+ // when - create a future that supports cancellation
300+ var params = new DocumentDiagnosticParams (getTextDocumentIdentifier ());
301+ var future = textDocumentService .diagnostic (params );
302+
303+ // then - verify that the future supports cancellation (can be cancelled)
304+ // The CompletableFutures.computeAsync returns a future that can be cancelled
305+ var wasCancelled = future .cancel (true );
306+
307+ // If the future completed before cancel was called, it returns false
308+ // If cancelled successfully, it returns true
309+ // Either way, we verify the future is in a terminal state
310+ assertThat (future .isDone ()).isTrue ();
311+
312+ // If cancellation was successful, verify the cancelled state
313+ if (wasCancelled ) {
314+ assertThat (future .isCancelled ()).isTrue ();
315+ }
316+ }
317+
292318 @ Test
293319 void testImplementation () throws ExecutionException , InterruptedException {
294320 var params = new ImplementationParams ();
You can’t perform that action at this time.
0 commit comments