Skip to content

Commit 00c6440

Browse files
authored
Merge pull request #3700 from 1c-syntax/copilot/support-cancellation-notification
Add LSP cancellation support in BSLTextDocumentService
2 parents ec77cec + 109ed93 commit 00c6440

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/BSLTextDocumentService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
105105
import org.eclipse.lsp4j.TextEdit;
106106
import org.eclipse.lsp4j.WorkspaceEdit;
107+
import org.eclipse.lsp4j.jsonrpc.CompletableFutures;
107108
import org.eclipse.lsp4j.jsonrpc.messages.Either;
108109
import org.eclipse.lsp4j.jsonrpc.messages.Either3;
109110
import 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
}

src/test/java/com/github/_1c_syntax/bsl/languageserver/BSLTextDocumentServiceTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)