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(); } 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 }); } );