Skip to content

Commit

Permalink
Merge pull request dotnet#36670 from jasonmalinowski/fix-editorconfig…
Browse files Browse the repository at this point in the history
…-feature-flag

Pass feature flags to the remote workspace
  • Loading branch information
jasonmalinowski authored Jun 25, 2019
2 parents 55a3205 + f95ecb7 commit 652a2e9
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public static async Task<RemoteHostClient> CreateAsync(Workspace workspace, bool
{
var inprocServices = new InProcRemoteServices(runCacheCleanup);

var remoteHostStream = await inprocServices.RequestServiceAsync(WellKnownRemoteHostServices.RemoteHostService, cancellationToken).ConfigureAwait(false);
// Create the RemotableDataJsonRpc before we create the remote host: this call implicitly sets up the remote IExperimentationService so that will be available for later calls
var remotableDataRpc = new RemotableDataJsonRpc(workspace, inprocServices.Logger, await inprocServices.RequestServiceAsync(WellKnownServiceHubServices.SnapshotService, cancellationToken).ConfigureAwait(false));
var remoteHostStream = await inprocServices.RequestServiceAsync(WellKnownRemoteHostServices.RemoteHostService, cancellationToken).ConfigureAwait(false);

var current = CreateClientId(Process.GetCurrentProcess().Id.ToString());
var instance = new InProcRemoteHostClient(current, workspace, inprocServices, new ReferenceCountedDisposable<RemotableDataJsonRpc>(remotableDataRpc), remoteHostStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Execution;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.VisualStudio.Threading;
Expand Down Expand Up @@ -67,6 +68,11 @@ public async Task RequestAssetAsync(int scopeId, Checksum[] checksums, string st
}
}

public Task<bool> IsExperimentEnabledAsync(string experimentName, CancellationToken cancellationToken)
{
return Task.FromResult(Workspace.Services.GetRequiredService<IExperimentationService>().IsExperimentEnabled(experimentName));
}

private bool ReportUnlessCanceled(Exception ex, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ public static async Task<ServiceHubRemoteHostClient> CreateWorkerAsync(Workspace
var current = CreateClientId(Process.GetCurrentProcess().Id.ToString());

var hostGroup = new HostGroup(current);
var remoteHostStream = await Connections.RequestServiceAsync(workspace, primary, WellKnownRemoteHostServices.RemoteHostService, hostGroup, timeout, cancellationToken).ConfigureAwait(false);

// Create the RemotableDataJsonRpc before we create the remote host: this call implicitly sets up the remote IExperimentationService so that will be available for later calls
var remotableDataRpc = new RemotableDataJsonRpc(
workspace, primary.Logger,
await Connections.RequestServiceAsync(workspace, primary, WellKnownServiceHubServices.SnapshotService, hostGroup, timeout, cancellationToken).ConfigureAwait(false));

var remoteHostStream = await Connections.RequestServiceAsync(workspace, primary, WellKnownRemoteHostServices.RemoteHostService, hostGroup, timeout, cancellationToken).ConfigureAwait(false);

var enableConnectionPool = workspace.Options.GetOption(RemoteHostOptions.EnableConnectionPool);
var maxConnection = workspace.Options.GetOption(RemoteHostOptions.MaxPoolConnection);

Expand Down
2 changes: 2 additions & 0 deletions src/Workspaces/Core/Portable/Log/FunctionId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,5 +456,7 @@ internal enum FunctionId

Intellisense_AsyncCompletion_Data,
Intellisense_CompletionProviders_Data,

SnapshotService_IsExperimentEnabledAsync,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public static void Set64bit(bool x64)
// these are OOP implementation itself should care. not features that consume OOP care
public const string ServiceHubServiceBase_Initialize = "Initialize";
public const string AssetService_RequestAssetAsync = "RequestAssetAsync";
public const string AssetService_IsExperimentEnabledAsync = "IsExperimentEnabledAsync";
}
}
1 change: 1 addition & 0 deletions src/Workspaces/Remote/Core/Services/AssetSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ protected AssetSource(AssetStorage assetStorage)
}

public abstract Task<IList<(Checksum, object)>> RequestAssetsAsync(int scopeId, ISet<Checksum> checksums, ISerializerService serializerService, CancellationToken cancellationToken);
public abstract Task<bool> IsExperimentEnabledAsync(string experimentName, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Composition;
using System.Threading;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Host.Mef;

namespace Microsoft.CodeAnalysis.Remote.Services
{
[ExportWorkspaceService(typeof(IExperimentationService), ServiceLayer.Host), Shared]
internal sealed class RemoteExperimentationService : IExperimentationService
{
public bool IsExperimentEnabled(string experimentName)
{
var assetSource = AssetStorage.Default.AssetSource;
return assetSource?.IsExperimentEnabledAsync(experimentName, CancellationToken.None).Result ?? false;
}
}
}
6 changes: 6 additions & 0 deletions src/Workspaces/Remote/Core/Shared/SimpleAssetSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Serialization;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Remote.Shared
{
Expand Down Expand Up @@ -41,5 +42,10 @@ public SimpleAssetSource(AssetStorage assetStorage, IReadOnlyDictionary<Checksum

return Task.FromResult<IList<(Checksum, object)>>(list);
}

public override Task<bool> IsExperimentEnabledAsync(string experimentName, CancellationToken cancellationToken)
{
return SpecializedTasks.False;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public JsonRpcAssetSource(SnapshotService owner) : base(owner.AssetStorage)
{
using (RoslynLogger.LogBlock(FunctionId.SnapshotService_RequestAssetAsync, GetRequestLogInfo, scopeId, checksums, cancellationToken))
{
// Surround this with a try/catch to report exceptions because we want to report any crashes here.
try
{
return await _owner.RunServiceAsync(() =>
Expand All @@ -50,6 +51,18 @@ public JsonRpcAssetSource(SnapshotService owner) : base(owner.AssetStorage)
}
}

public override async Task<bool> IsExperimentEnabledAsync(string experimentName, CancellationToken cancellationToken)
{
using (RoslynLogger.LogBlock(FunctionId.SnapshotService_IsExperimentEnabledAsync, experimentName, cancellationToken))
{
return await _owner.RunServiceAsync(() =>
{
return _owner.InvokeAsync<bool>(WellKnownServiceHubServices.AssetService_IsExperimentEnabledAsync,
new object[] { experimentName }, cancellationToken);
}, cancellationToken).ConfigureAwait(false);
}
}

private bool ReportUnlessCanceled(Exception ex, CancellationToken cancellationToken)
{
if (!cancellationToken.IsCancellationRequested && _owner.IsDisposed)
Expand Down

0 comments on commit 652a2e9

Please sign in to comment.