From d0b3389159242e6522cc5e2582db55006d433c63 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 11 Mar 2024 14:16:39 -0700 Subject: [PATCH] Remove workspace option --- ...alyzer.InProcOrRemoteHostAnalyzerRunner.cs | 24 ++- .../WorkspaceConfigurationOptionsStorage.cs | 6 +- .../Def/Options/VisualStudioOptionStorage.cs | 1 - .../Services/ServiceHubServicesTests.cs | 138 ++++++------------ .../IWorkspaceConfigurationService.cs | 9 +- ...tionState.CompilationTracker_Generators.cs | 3 - 6 files changed, 59 insertions(+), 122 deletions(-) diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.InProcOrRemoteHostAnalyzerRunner.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.InProcOrRemoteHostAnalyzerRunner.cs index 0c137f89f22c5..411b95df18d8d 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.InProcOrRemoteHostAnalyzerRunner.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.InProcOrRemoteHostAnalyzerRunner.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; -using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -14,11 +13,9 @@ using Microsoft.CodeAnalysis.Diagnostics.Telemetry; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Remote; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; -using Microsoft.CodeAnalysis.Simplification; using Microsoft.CodeAnalysis.Workspaces.Diagnostics; using Roslyn.Utilities; @@ -90,21 +87,18 @@ async Task> GetSourceGeneratorDiagnosticsAsync(Project project, CancellationToken cancellationToken) { var options = project.Solution.Services.GetRequiredService().Options; - if (!options.RunSourceGeneratorsInSameProcessOnly) + var remoteHostClient = await RemoteHostClient.TryGetClientAsync(project, cancellationToken).ConfigureAwait(false); + if (remoteHostClient != null) { - var remoteHostClient = await RemoteHostClient.TryGetClientAsync(project, cancellationToken).ConfigureAwait(false); - if (remoteHostClient != null) - { - var result = await remoteHostClient.TryInvokeAsync>( - project.Solution, - invocation: (service, solutionInfo, cancellationToken) => service.GetSourceGeneratorDiagnosticsAsync(solutionInfo, project.Id, cancellationToken), - cancellationToken).ConfigureAwait(false); + var result = await remoteHostClient.TryInvokeAsync>( + project.Solution, + invocation: (service, solutionInfo, cancellationToken) => service.GetSourceGeneratorDiagnosticsAsync(solutionInfo, project.Id, cancellationToken), + cancellationToken).ConfigureAwait(false); - if (!result.HasValue) - return []; + if (!result.HasValue) + return []; - return await result.Value.ToDiagnosticsAsync(project, cancellationToken).ConfigureAwait(false); - } + return await result.Value.ToDiagnosticsAsync(project, cancellationToken).ConfigureAwait(false); } return await project.GetSourceGeneratorDiagnosticsAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs b/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs index f525f1f1a0602..df4a8ed19d97e 100644 --- a/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs +++ b/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs @@ -16,8 +16,7 @@ public static WorkspaceConfigurationOptions GetWorkspaceConfigurationOptions(thi EnableOpeningSourceGeneratedFiles: globalOptions.GetOption(EnableOpeningSourceGeneratedFilesInWorkspace) ?? globalOptions.GetOption(EnableOpeningSourceGeneratedFilesInWorkspaceFeatureFlag), DisableRecoverableText: globalOptions.GetOption(DisableRecoverableText), - ValidateCompilationTrackerStates: globalOptions.GetOption(ValidateCompilationTrackerStates), - RunSourceGeneratorsInSameProcessOnly: globalOptions.GetOption(RunSourceGeneratorsInSameProcessOnly)); + ValidateCompilationTrackerStates: globalOptions.GetOption(ValidateCompilationTrackerStates)); public static readonly Option2 Database = new( "dotnet_storage_database", WorkspaceConfigurationOptions.Default.CacheStorage, serializer: EditorConfigValueSerializer.CreateSerializerForEnum()); @@ -28,9 +27,6 @@ public static WorkspaceConfigurationOptions GetWorkspaceConfigurationOptions(thi public static readonly Option2 ValidateCompilationTrackerStates = new( "dotnet_validate_compilation_tracker_states", WorkspaceConfigurationOptions.Default.ValidateCompilationTrackerStates); - public static readonly Option2 RunSourceGeneratorsInSameProcessOnly = new( - "dotnet_run_source_generators_in_same_process_only", WorkspaceConfigurationOptions.Default.RunSourceGeneratorsInSameProcessOnly); - /// /// This option allows the user to enable this. We are putting this behind a feature flag for now since we could have extensions /// surprised by this and we want some time to work through those issues. diff --git a/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs b/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs index 669a1e31877f5..8b5162180b5d2 100644 --- a/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs +++ b/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs @@ -429,7 +429,6 @@ public bool TryFetch(LocalUserRegistryOptionPersister persister, OptionKey2 opti {"visual_studio_workspace_partial_load_mode", new FeatureFlagStorage(@"Roslyn.PartialLoadMode")}, {"dotnet_disable_recoverable_text", new FeatureFlagStorage(@"Roslyn.DisableRecoverableText")}, {"dotnet_validate_compilation_tracker_states", new FeatureFlagStorage(@"Roslyn.ValidateCompilationTrackerStates")}, - {"dotnet_run_source_generators_in_same_process_only", new FeatureFlagStorage(@"Roslyn.RunSourceGeneratorsInSameProcessOnly")}, {"dotnet_enable_diagnostics_in_source_generated_files", new RoamingProfileStorage("TextEditor.Roslyn.Specific.EnableDiagnosticsInSourceGeneratedFilesExperiment")}, {"dotnet_enable_diagnostics_in_source_generated_files_feature_flag", new FeatureFlagStorage(@"Roslyn.EnableDiagnosticsInSourceGeneratedFiles")}, {"dotnet_enable_opening_source_generated_files_in_workspace", new RoamingProfileStorage("TextEditor.Roslyn.Specific.EnableOpeningSourceGeneratedFilesInWorkspaceExperiment")}, diff --git a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs index 34f888fea9dbe..8a645c6e273df 100644 --- a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs +++ b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs @@ -402,42 +402,15 @@ void DoPermute(int start, int end) } private static async Task TestInProcAndRemoteWorkspace( - bool syncWithRemoteServer, params ImmutableArray<(string hintName, SourceText text)>[] values) + params ImmutableArray<(string hintName, SourceText text)>[] values) { // Try every permutation of these values. foreach (var permutation in Permute(values)) - { - var gotException = false; - try - { - await TestInProcAndRemoteWorkspaceWorker(syncWithRemoteServer, permutation); - } - catch (XunitException) - { - gotException = true; - } - - // If we're syncing to the remove server, we should get no exceptions, since the data should be matched - // between both. If we're not syncing, we should see a failure since the two processes will disagree on - // the contents. - Assert.Equal(syncWithRemoteServer, !gotException); - } - } - - [ExportWorkspaceService(typeof(IWorkspaceConfigurationService), ServiceLayer.Test), SharedAttribute, PartNotDiscoverable] - private sealed class NoSyncWorkspaceConfigurationService : IWorkspaceConfigurationService - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public NoSyncWorkspaceConfigurationService() - { - } - - public WorkspaceConfigurationOptions Options => WorkspaceConfigurationOptions.Default with { RunSourceGeneratorsInSameProcessOnly = true }; + await TestInProcAndRemoteWorkspaceWorker(permutation); } private static async Task TestInProcAndRemoteWorkspaceWorker( - bool syncWithRemoteServer, ImmutableArray> values) + ImmutableArray> values) { var throwIfCalled = false; ImmutableArray<(string hintName, SourceText text)> sourceTexts = default; @@ -450,7 +423,7 @@ private static async Task TestInProcAndRemoteWorkspaceWorker( return sourceTexts; }); - using var localWorkspace = CreateWorkspace(syncWithRemoteServer ? [] : [typeof(NoSyncWorkspaceConfigurationService)]); + using var localWorkspace = CreateWorkspace(); DocumentId tempDocId; @@ -541,204 +514,183 @@ private static SourceText CreateStreamText(string content, bool useBOM, bool use } } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree1(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree1() { await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(Guid.NewGuid().ToString())))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree2(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree2() { var sourceText = CreateText(Guid.NewGuid().ToString()); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", sourceText)), ImmutableArray.Create(("SG.cs", sourceText))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree3(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree3() { var sourceText = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(sourceText))), ImmutableArray.Create(("SG.cs", CreateText(sourceText)))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree4(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree4() { await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(Guid.NewGuid().ToString()))), ImmutableArray.Create(("SG.cs", CreateText(Guid.NewGuid().ToString())))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree5(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree5() { await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(Guid.NewGuid().ToString()))), ImmutableArray.Create(("NewName.cs", CreateText(Guid.NewGuid().ToString())))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree6(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree6() { var sourceText = CreateText(Guid.NewGuid().ToString()); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", sourceText)), ImmutableArray.Create(("NewName.cs", sourceText))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree7(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree7() { var sourceText = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(sourceText))), ImmutableArray.Create(("NewName.cs", CreateText(sourceText)))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree8(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree8() { await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(Guid.NewGuid().ToString()))), ImmutableArray.Create(("NewName.cs", CreateText(Guid.NewGuid().ToString())))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree9(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree9() { await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText("X", Encoding.ASCII))), ImmutableArray.Create(("SG.cs", CreateText("X", Encoding.UTF8)))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree10(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree10() { await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText("X", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha1))), ImmutableArray.Create(("SG.cs", CreateText("X", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha256)))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree11(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree11() { await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(Guid.NewGuid().ToString()))), ImmutableArray<(string, SourceText)>.Empty); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree12(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree12() { await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray<(string, SourceText)>.Empty, ImmutableArray.Create(("SG.cs", CreateText(Guid.NewGuid().ToString())))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree13(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree13() { var contents = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(contents))), ImmutableArray.Create(("SG.cs", CreateText(contents)), ("SG1.cs", CreateText(contents)))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree14(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree14() { var contents = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(contents))), ImmutableArray.Create(("SG.cs", CreateText(contents)), ("SG1.cs", CreateText("Other")))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree15(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree15() { var contents = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(contents))), ImmutableArray.Create(("SG1.cs", CreateText(contents)), ("SG.cs", CreateText("Other")))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree16(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree16() { var contents = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(contents))), ImmutableArray.Create(("SG1.cs", CreateText("Other")), ("SG.cs", CreateText(contents)))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree17(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree17() { var contents = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateText(contents))), ImmutableArray.Create(("SG1.cs", CreateText("Other")), ("SG.cs", CreateText(contents))), ImmutableArray<(string, SourceText)>.Empty); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree18(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree18() { var contents = CreateText(Guid.NewGuid().ToString()); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG1.cs", contents), ("SG2.cs", contents))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree19(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree19() { var contents = CreateText(Guid.NewGuid().ToString()); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG1.cs", contents), ("SG2.cs", contents)), ImmutableArray.Create(("SG2.cs", contents), ("SG1.cs", contents))); } - [Theory, CombinatorialData] - public async Task InProcAndRemoteWorkspaceAgree20(bool syncWithRemoteServer) + [Fact] + public async Task InProcAndRemoteWorkspaceAgree20() { var contents = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG1.cs", CreateText(contents)), ("SG2.cs", CreateText(contents))), ImmutableArray.Create(("SG2.cs", CreateText(contents)), ("SG1.cs", CreateText(contents)))); } [Theory, CombinatorialData] public async Task InProcAndRemoteWorkspaceAgree21( - bool syncWithRemoteServer, bool useBOM1, bool useMemoryStream1, bool useBOM2, bool useMemoryStream2) + bool useBOM1, bool useMemoryStream1, bool useBOM2, bool useMemoryStream2) { var contents = Guid.NewGuid().ToString(); await TestInProcAndRemoteWorkspace( - syncWithRemoteServer, ImmutableArray.Create(("SG.cs", CreateStreamText(contents, useBOM: useBOM1, useMemoryStream: useMemoryStream1))), ImmutableArray.Create(("SG.cs", CreateStreamText(contents, useBOM: useBOM2, useMemoryStream: useMemoryStream2)))); } diff --git a/src/Workspaces/Core/Portable/Workspace/IWorkspaceConfigurationService.cs b/src/Workspaces/Core/Portable/Workspace/IWorkspaceConfigurationService.cs index 17de818593abd..c5db31d00e001 100644 --- a/src/Workspaces/Core/Portable/Workspace/IWorkspaceConfigurationService.cs +++ b/src/Workspaces/Core/Portable/Workspace/IWorkspaceConfigurationService.cs @@ -39,11 +39,11 @@ internal readonly record struct WorkspaceConfigurationOptions( [property: DataMember(Order = 2)] bool DisableRecoverableText = false, [property: DataMember(Order = 3)] bool ValidateCompilationTrackerStates = #if DEBUG // We will default this on in DEBUG builds - true, + true #else - false, + false #endif - [property: DataMember(Order = 4)] bool RunSourceGeneratorsInSameProcessOnly = false) + ) { public WorkspaceConfigurationOptions() : this(CacheStorage: StorageDatabase.SQLite) @@ -59,6 +59,5 @@ public WorkspaceConfigurationOptions() public static readonly WorkspaceConfigurationOptions RemoteDefault = new( CacheStorage: StorageDatabase.None, EnableOpeningSourceGeneratedFiles: false, - DisableRecoverableText: false, - RunSourceGeneratorsInSameProcessOnly: false); + DisableRecoverableText: false); } diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker_Generators.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker_Generators.cs index dd008da52fb21..4f077e2a9ebaf 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker_Generators.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker_Generators.cs @@ -102,9 +102,6 @@ private partial class CompilationTracker : ICompilationTracker CancellationToken cancellationToken) { var solution = compilationState.SolutionState; - var options = solution.Services.GetRequiredService().Options; - if (options.RunSourceGeneratorsInSameProcessOnly) - return null; var client = await RemoteHostClient.TryGetClientAsync(solution.Services, cancellationToken).ConfigureAwait(false); if (client is null)