diff --git a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractPullDiagnosticHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractPullDiagnosticHandler.cs index 9feca8653fab0..eb2350d1b7d90 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractPullDiagnosticHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractPullDiagnosticHandler.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; @@ -117,7 +116,7 @@ protected abstract ValueTask> GetOrderedDiagno /// Used by public workspace pull diagnostics to allow it to keep the connection open until /// changes occur to avoid the client spamming the server with requests. /// - protected virtual Task WaitForChangesAsync(RequestContext context, CancellationToken cancellationToken) + protected virtual Task WaitForChangesAsync(ILspLogger logger, CancellationToken cancellationToken) { return Task.CompletedTask; } @@ -191,14 +190,18 @@ await ComputeAndReportCurrentDiagnosticsAsync( } } + // Clear out the context to avoid retaining memory + var logger = context.Logger; + context = default; + // Some implementations of the spec will re-open requests as soon as we close them, spamming the server. // In those cases, we wait for the implementation to indicate that changes have occurred, then we close the connection // so that the client asks us again. - await WaitForChangesAsync(context, cancellationToken).ConfigureAwait(false); + await WaitForChangesAsync(logger, cancellationToken).ConfigureAwait(false); // If we had a progress object, then we will have been reporting to that. Otherwise, take what we've been // collecting and return that. - context.TraceInformation($"{this.GetType()} finished getting diagnostics"); + logger.LogInformation($"{this.GetType()} finished getting diagnostics"); return CreateReturn(progress); } diff --git a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/Public/PublicWorkspacePullDiagnosticsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/Public/PublicWorkspacePullDiagnosticsHandler.cs index 4815fd9c3bc54..f85dd74a6e347 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/Public/PublicWorkspacePullDiagnosticsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/Public/PublicWorkspacePullDiagnosticsHandler.cs @@ -11,8 +11,8 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.EditAndContinue; using Microsoft.CodeAnalysis.Options; +using Microsoft.CommonLanguageServerProtocol.Framework; using Microsoft.VisualStudio.LanguageServer.Protocol; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public; @@ -159,7 +159,7 @@ private void UpdateLspChanged() Interlocked.Exchange(ref _lspChanged, 1); } - protected override async Task WaitForChangesAsync(RequestContext context, CancellationToken cancellationToken) + protected override async Task WaitForChangesAsync(ILspLogger logger, CancellationToken cancellationToken) { // Spin waiting until our LSP change flag has been set. When the flag is set (meaning LSP has changed), // we reset the flag to false and exit out of the loop allowing the request to close. @@ -170,7 +170,7 @@ protected override async Task WaitForChangesAsync(RequestContext context, Cancel await Task.Delay(TimeSpan.FromMilliseconds(100), cancellationToken).ConfigureAwait(false); } - context.TraceInformation("Closing workspace/diagnostics request"); + logger.LogInformation("Closing workspace/diagnostics request"); // We've hit a change, so we close the current request to allow the client to open a new one. return; } diff --git a/src/Features/LanguageServer/Protocol/Handler/RequestContext.cs b/src/Features/LanguageServer/Protocol/Handler/RequestContext.cs index 9ad6cfcd1abca..d8e96d5f02784 100644 --- a/src/Features/LanguageServer/Protocol/Handler/RequestContext.cs +++ b/src/Features/LanguageServer/Protocol/Handler/RequestContext.cs @@ -111,6 +111,8 @@ public RequestContext( Method = method; } + public ILspLogger Logger => _logger; + public ClientCapabilities GetRequiredClientCapabilities() { return _clientCapabilities is null