From 2855dc2500871c6bd9b2cd638784c2a79ea5c146 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Thu, 8 May 2025 18:13:20 -0700 Subject: [PATCH] Cancel running requests when the connection terminates --- .../AbstractLanguageServer.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs index 89f6d1b0f1aa0..8dfaaf906cac6 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs @@ -65,6 +65,9 @@ protected AbstractLanguageServer( _jsonRpc = jsonRpc; TypeRefResolver = typeRefResolver ?? TypeRef.DefaultResolver.Instance; + // We have no need to continue running LSP requests after the connection is closed. + _jsonRpc.CancelLocallyInvokedMethodsWhenConnectionIsClosed = true; + _jsonRpc.AddLocalRpcTarget(this); _jsonRpc.Disconnected += JsonRpc_Disconnected; _lspServices = new Lazy(() => ConstructLspServices());