diff --git a/src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostClientServiceFactory.RemoteHostClientService.cs b/src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostClientServiceFactory.RemoteHostClientService.cs index 3f9282bc8163ca26e5c6a90b1c7db53df7e57983..be6b244772a605275434d6ebc1fbeedd911297eb 100644 --- a/src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostClientServiceFactory.RemoteHostClientService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostClientServiceFactory.RemoteHostClientService.cs @@ -5,16 +5,20 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Execution; using Microsoft.CodeAnalysis.Internal.Log; +using Microsoft.CodeAnalysis.Shared.Options; +using Microsoft.VisualStudio.Settings; +using Microsoft.VisualStudio.Shell.Settings; using Roslyn.Utilities; namespace Microsoft.VisualStudio.LanguageServices.Remote { internal partial class RemoteHostClientServiceFactory { - public class RemoteHostClientService : IRemoteHostClientService + public class RemoteHostClientService : ForegroundThreadAffinitizedObject, IRemoteHostClientService { private readonly Workspace _workspace; private readonly IDiagnosticAnalyzerService _analyzerService; @@ -25,7 +29,8 @@ public class RemoteHostClientService : IRemoteHostClientService private CancellationTokenSource _shutdownCancellationTokenSource; private Task _instanceTask; - public RemoteHostClientService(Workspace workspace, IDiagnosticAnalyzerService analyzerService) + public RemoteHostClientService(Workspace workspace, IDiagnosticAnalyzerService analyzerService) : + base() { _gate = new object(); @@ -51,6 +56,12 @@ public void Enable() return; } + if (!FeaturesEnabled()) + { + // none of features that require OOP is enabled. + return; + } + // log that remote host is enabled Logger.Log(FunctionId.RemoteHostClientService_Enabled, KeyValueLogMessage.NoProperty); @@ -187,6 +198,44 @@ private void OnConnectionChanged(object sender, bool connected) // crash right away when connection is closed FatalError.Report(new Exception("Connection to remote host closed")); } + + private bool FeaturesEnabled() + { + if (ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_workspace.Options, LanguageNames.CSharp)) + { + return true; + } + + if (TestImpactEnabled()) + { + return true; + } + + // TODO: add check for code lens. + return false; + } + + private bool TestImpactEnabled() + { + const string TestImpactPath = @"CodeAnalysis\TestImpact\IsGloballyEnabled"; + const string KeyName = "Value"; + + // TODO: think about how to get rid of this code. since we don't want any code that require foreground + // thread to run + AssertIsForeground(); + + var shellSettingsManager = new ShellSettingsManager(Shell.ServiceProvider.GlobalProvider); + var writeableSettingsStore = shellSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); + + if (writeableSettingsStore.PropertyExists(TestImpactPath, KeyName)) + { + return writeableSettingsStore.GetBoolean(TestImpactPath, KeyName); + } + else + { + return false; + } + } } } }