File tree Expand file tree Collapse file tree 2 files changed +27
-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 +27
-3
lines changed Original file line number Diff line number Diff line change 103103import org .eclipse .lsp4j .TextDocumentContentChangeEvent ;
104104import org .eclipse .lsp4j .TextEdit ;
105105import org .eclipse .lsp4j .WorkspaceEdit ;
106+ import org .eclipse .lsp4j .jsonrpc .CompletableFutures ;
106107import org .eclipse .lsp4j .jsonrpc .messages .Either ;
107108import org .eclipse .lsp4j .jsonrpc .messages .Either3 ;
108109import org .eclipse .lsp4j .services .TextDocumentService ;
@@ -747,9 +748,13 @@ private void processDocumentChange(
747748 waitFuture = CompletableFuture .completedFuture (null );
748749 }
749750
750- return waitFuture .thenApplyAsync (
751- ignored -> supplier .get (),
752- executorService
751+ return CompletableFutures .computeAsync (
752+ executorService ,
753+ cancelChecker -> {
754+ waitFuture .join ();
755+ cancelChecker .checkCanceled ();
756+ return supplier .get ();
757+ }
753758 );
754759 }
755760}
Original file line number Diff line number Diff line change 4949import java .nio .charset .StandardCharsets ;
5050import java .util .ArrayList ;
5151import java .util .List ;
52+ import java .util .concurrent .CancellationException ;
5253import java .util .concurrent .ExecutionException ;
5354
5455import static org .assertj .core .api .Assertions .assertThat ;
@@ -288,6 +289,24 @@ void testRenamePrepare() {
288289 assertThat (result ).isNotNull ();
289290 }
290291
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
300+ var params = new DocumentDiagnosticParams (getTextDocumentIdentifier ());
301+ var future = textDocumentService .diagnostic (params );
302+
303+ // Cancel the future before it completes
304+ future .cancel (true );
305+
306+ // then - future should be cancelled
307+ assertThat (future .isCancelled ()).isTrue ();
308+ }
309+
291310 private File getTestFile () {
292311 return new File ("./src/test/resources/BSLTextDocumentServiceTest.bsl" );
293312 }
You can’t perform that action at this time.
0 commit comments