Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove workspace option #72490

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics.EngineV2;
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;

Expand Down Expand Up @@ -90,21 +87,18 @@ async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisRes
public static async Task<ImmutableArray<Diagnostic>> GetSourceGeneratorDiagnosticsAsync(Project project, CancellationToken cancellationToken)
{
var options = project.Solution.Services.GetRequiredService<IWorkspaceConfigurationService>().Options;
if (!options.RunSourceGeneratorsInSameProcessOnly)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view with whitespace off.

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<IRemoteDiagnosticAnalyzerService, ImmutableArray<DiagnosticData>>(
project.Solution,
invocation: (service, solutionInfo, cancellationToken) => service.GetSourceGeneratorDiagnosticsAsync(solutionInfo, project.Id, cancellationToken),
cancellationToken).ConfigureAwait(false);
var result = await remoteHostClient.TryInvokeAsync<IRemoteDiagnosticAnalyzerService, ImmutableArray<DiagnosticData>>(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<StorageDatabase> Database = new(
"dotnet_storage_database", WorkspaceConfigurationOptions.Default.CacheStorage, serializer: EditorConfigValueSerializer.CreateSerializerForEnum<StorageDatabase>());
Expand All @@ -28,9 +27,6 @@ public static WorkspaceConfigurationOptions GetWorkspaceConfigurationOptions(thi
public static readonly Option2<bool> ValidateCompilationTrackerStates = new(
"dotnet_validate_compilation_tracker_states", WorkspaceConfigurationOptions.Default.ValidateCompilationTrackerStates);

public static readonly Option2<bool> RunSourceGeneratorsInSameProcessOnly = new(
"dotnet_run_source_generators_in_same_process_only", WorkspaceConfigurationOptions.Default.RunSourceGeneratorsInSameProcessOnly);

/// <summary>
/// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
Expand Down
138 changes: 45 additions & 93 deletions src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we had tests actually vvalidating that without this option that our host/oop get out of sync. since hte option is gone and both most be in sync, all the tests validate that.


[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<ImmutableArray<(string hintName, SourceText text)>> values)
ImmutableArray<ImmutableArray<(string hintName, SourceText text)>> values)
{
var throwIfCalled = false;
ImmutableArray<(string hintName, SourceText text)> sourceTexts = default;
Expand All @@ -450,7 +423,7 @@ private static async Task TestInProcAndRemoteWorkspaceWorker(
return sourceTexts;
});

using var localWorkspace = CreateWorkspace(syncWithRemoteServer ? [] : [typeof(NoSyncWorkspaceConfigurationService)]);
using var localWorkspace = CreateWorkspace();

DocumentId tempDocId;

Expand Down Expand Up @@ -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))));
}
Expand Down
Loading
Loading