From 12cf7cd0ed02bf92214644cdee410afd8e9c81ed Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Thu, 9 May 2024 15:06:44 -0700 Subject: [PATCH] Avoid image load due to co-hosting and CLaSP There's a long discussion about this, but it turns out that CLaSP relies on MEF metadata that exposes System.Types. This means that MEF must load assemblies in order to produce metadata. Recently, one of our co-hosting endpoints unintentionally pulled in Microsoft.CodeAnalysis.Razor.Workspaces by using a protocol type from MS.CA.Razor.Workspaces as generic type argument. Since, CLaSP loads the type, it had to additionally load MS.CA.Razor.Workspaces to satisfy the generic argument. The fix is easy -- just don't use that protocol type. However, that's not sustainable and this change has started a conversation about potential re-architecture to CLaSP to avoid eagerly loading assemblies. --- .../LanguageClient/Cohost/CohostUriPresentationEndpoint.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostUriPresentationEndpoint.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostUriPresentationEndpoint.cs index bea9e21b5a2..11db58b0f4f 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostUriPresentationEndpoint.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostUriPresentationEndpoint.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.CodeAnalysis.Razor.Protocol.DocumentPresentation; using Microsoft.CodeAnalysis.Razor.Remote; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; @@ -25,7 +24,7 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal class CohostUriPresentationEndpoint(IRemoteClientProvider remoteClientProvider, ILoggerFactory loggerFactory) - : AbstractRazorCohostDocumentRequestHandler, IDynamicRegistrationProvider + : AbstractRazorCohostDocumentRequestHandler, IDynamicRegistrationProvider { private readonly IRemoteClientProvider _remoteClientProvider = remoteClientProvider; private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); @@ -51,10 +50,10 @@ internal class CohostUriPresentationEndpoint(IRemoteClientProvider remoteClientP return null; } - protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(UriPresentationParams request) + protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(VSInternalUriPresentationParams request) => request.TextDocument.ToRazorTextDocumentIdentifier(); - protected override async Task HandleRequestAsync(UriPresentationParams request, RazorCohostRequestContext context, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(VSInternalUriPresentationParams request, RazorCohostRequestContext context, CancellationToken cancellationToken) { var razorDocument = context.TextDocument.AssumeNotNull();