未验证 提交 1b17eae2 编写于 作者: T Tomáš Matoušek 提交者: GitHub

Move RazorRemoteHostClient functionality to ExternalAccess.Razor (#43770)

* Move RazorRemoteHostClient functionality to ExternalAccess.Razor

* Add file
上级 a90cf45f
// 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<RazorRemoteHostClient?> CreateAsync(Workspace workspace, CancellationToken cancellationToken = default)
{
var clientFactory = workspace.Services.GetRequiredService<IRemoteHostClientService>();
var client = await clientFactory.TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
return client == null ? null : new RazorRemoteHostClient(client, GetServiceName(workspace));
}
public Task<Optional<T>> TryRunRemoteAsync<T>(string targetName, Solution? solution, IReadOnlyList<object?> arguments, CancellationToken cancellationToken)
=> _client.TryRunRemoteAsync<T>(_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<IExperimentationService>().IsExperimentEnabled(
WellKnownExperimentNames.RoslynOOP64bit);
}
Interlocked.CompareExchange(
ref s_lazyServiceName, x64 ? "razorLanguageService64" : "razorLanguageService", null);
}
return s_lazyServiceName;
}
public static readonly Option<bool> OOP64Bit = new Option<bool>(
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
}
}
......@@ -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;
......
......@@ -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<RazorLanguageServiceClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken = default)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册