diff --git a/src/Tools/ExternalAccess/Razor/RazorRemoteHostClient.cs b/src/Tools/ExternalAccess/Razor/RazorRemoteHostClient.cs new file mode 100644 index 0000000000000000000000000000000000000000..8276747ab49ad21b67ad29d29b6e11d2be083629 --- /dev/null +++ b/src/Tools/ExternalAccess/Razor/RazorRemoteHostClient.cs @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// 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.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Experiments; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Remote; + +namespace Microsoft.CodeAnalysis.ExternalAccess.Razor +{ + internal sealed class RazorRemoteHostClient + { + private readonly RemoteHostClient _client; + private readonly string _serviceName; + + internal RazorRemoteHostClient(RemoteHostClient client, string serviceName) + { + _client = client; + _serviceName = serviceName; + } + + public static async Task CreateAsync(Workspace workspace, CancellationToken cancellationToken = default) + { + var clientFactory = workspace.Services.GetRequiredService(); + var client = await clientFactory.TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); + return client == null ? null : new RazorRemoteHostClient(client, GetServiceName(workspace)); + } + + public Task> TryRunRemoteAsync(string targetName, Solution? solution, IReadOnlyList arguments, CancellationToken cancellationToken) + => _client.TryRunRemoteAsync(_serviceName, targetName, solution, arguments, callbackTarget: null, cancellationToken); + + #region support a/b testing. after a/b testing, we can remove all this code + + private static string? s_lazyServiceName = null; + + private static string GetServiceName(Workspace workspace) + { + if (s_lazyServiceName == null) + { + var x64 = workspace.Options.GetOption(OOP64Bit); + if (!x64) + { + x64 = workspace.Services.GetRequiredService().IsExperimentEnabled( + WellKnownExperimentNames.RoslynOOP64bit); + } + + Interlocked.CompareExchange( + ref s_lazyServiceName, x64 ? "razorLanguageService64" : "razorLanguageService", null); + } + + return s_lazyServiceName; + } + + public static readonly Option OOP64Bit = new Option( + nameof(InternalFeatureOnOffOptions), nameof(OOP64Bit), defaultValue: false, + storageLocations: new LocalUserProfileStorageLocation(InternalFeatureOnOffOptions.LocalRegistryPath + nameof(OOP64Bit))); + + private static class InternalFeatureOnOffOptions + { + internal const string LocalRegistryPath = @"Roslyn\Internal\OnOff\Features\"; + } + + #endregion + } +} diff --git a/src/VisualStudio/Razor/RazorLanguageServiceClient.cs b/src/VisualStudio/Razor/RazorLanguageServiceClient.cs index 1b9387a5059cb659c70d84386d800cfe0972b713..752a73726479c3d8b3da6b7a11db4b1f6dfdd690 100644 --- a/src/VisualStudio/Razor/RazorLanguageServiceClient.cs +++ b/src/VisualStudio/Razor/RazorLanguageServiceClient.cs @@ -15,6 +15,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { // Used in https://github.com/aspnet/AspNetCore-Tooling/tree/master/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/OOPTagHelperResolver.cs + [Obsolete("Use Microsoft.CodeAnalysis.ExternalAccess.Razor.RazorRemoteHostClient instead")] internal sealed class RazorLanguageServiceClient { private readonly RemoteHostClient _client; diff --git a/src/VisualStudio/Razor/RazorLanguageServiceClientFactory.cs b/src/VisualStudio/Razor/RazorLanguageServiceClientFactory.cs index 3cd1d016739414d3f517eedc7967f966c904ccf6..4995a595acce717916339f62c9733b8faa531b26 100644 --- a/src/VisualStudio/Razor/RazorLanguageServiceClientFactory.cs +++ b/src/VisualStudio/Razor/RazorLanguageServiceClientFactory.cs @@ -2,6 +2,7 @@ // 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.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; @@ -11,6 +12,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { + [Obsolete("Use Microsoft.CodeAnalysis.ExternalAccess.Razor.RazorRemoteHostClient instead")] internal static class RazorLanguageServiceClientFactory { public static async Task CreateAsync(Workspace workspace, CancellationToken cancellationToken = default)