From b5158d7b7b2e70b26fbbc057d1a1b1b41b63e0c2 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Thu, 6 Jun 2024 10:10:04 -0700 Subject: [PATCH] Ensure that the `RazorLanguageServerHost` is disposed --- .../RazorLanguageServerClient.cs | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/RazorLanguageServerClient.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/RazorLanguageServerClient.cs index 8219caf0be..70e49a239c 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/RazorLanguageServerClient.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/RazorLanguageServerClient.cs @@ -128,6 +128,24 @@ internal class RazorLanguageServerClient( } } + private async Task EnsureCleanedUpServerAsync() + { + if (_host is null) + { + // Server was already cleaned up + return; + } + + if (_host is not null) + { + // Server still hasn't shutdown, wait for it to shutdown + await _host.WaitForExitAsync().ConfigureAwait(false); + + _host.Dispose(); + _host = null; + } + } + internal static IEnumerable> GetRelevantContainedLanguageClientsAndMetadata(ILanguageServiceBroker2 languageServiceBroker) { var relevantClientAndMetadata = new List>(); @@ -186,21 +204,6 @@ internal class RazorLanguageServerClient( _lspServerActivationTracker.Activated(); } - private async Task EnsureCleanedUpServerAsync() - { - if (_host is null) - { - // Server was already cleaned up - return; - } - - if (_host is not null) - { - // Server still hasn't shutdown, wait for it to shutdown - await _host.WaitForExitAsync().ConfigureAwait(false); - } - } - public Task AttachForCustomMessageAsync(JsonRpc rpc) => Task.CompletedTask; public Task OnServerInitializeFailedAsync(ILanguageClientInitializationInfo initializationState)