From 68680df8058d0a374f3ff33ac4b4dd182276bfa8 Mon Sep 17 00:00:00 2001 From: Yannick Cholette Date: Tue, 13 Feb 2024 15:52:39 -0500 Subject: [PATCH 1/2] Set task as Canceled based on token --- src/JsonRpc/ResponseRouter.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/JsonRpc/ResponseRouter.cs b/src/JsonRpc/ResponseRouter.cs index d66afc528..dfff2c42e 100644 --- a/src/JsonRpc/ResponseRouter.cs +++ b/src/JsonRpc/ResponseRouter.cs @@ -101,10 +101,10 @@ public async Task Returning(CancellationToken cancellation var tcs = new TaskCompletionSource(); _router.Requests.TryAdd(nextId, ( _method, tcs )); - cancellationToken.ThrowIfCancellationRequested(); - try { + cancellationToken.ThrowIfCancellationRequested(); + _router.OutputHandler.Value.Send( new OutgoingRequest { @@ -117,6 +117,13 @@ public async Task Returning(CancellationToken cancellation () => { if (tcs.Task.IsCompleted) return; + + if (cancellationToken.IsCancellationRequested) + { + tcs.SetCanceled(); + return; + } + _router.CancelRequest(new CancelParams { Id = nextId }); } ); From 71ef7e412a95305a2677cd9ef9ec82620072fef2 Mon Sep 17 00:00:00 2001 From: Yannick Cholette Date: Tue, 13 Feb 2024 15:56:30 -0500 Subject: [PATCH 2/2] Add Shutdown(CancellationToken token) --- src/Client/LanguageClient.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Client/LanguageClient.cs b/src/Client/LanguageClient.cs index 22c7004df..1c97edd0e 100644 --- a/src/Client/LanguageClient.cs +++ b/src/Client/LanguageClient.cs @@ -420,10 +420,20 @@ private void RegisterCapabilities(ClientCapabilities capabilities) } public async Task Shutdown() + { + await Shutdown(CancellationToken.None); + } + + public async Task Shutdown(CancellationToken token) { if (_connection.IsOpen) { - await this.RequestShutdown().ConfigureAwait(false); + try + { + await this.RequestShutdown(token).ConfigureAwait(false); + } + catch (TaskCanceledException) { } + this.SendExit(); }