diff --git a/src/EditorFeatures/Test/EditAndContinue/EditAndContinueWorkspaceServiceTests.cs b/src/EditorFeatures/Test/EditAndContinue/EditAndContinueWorkspaceServiceTests.cs index e95bc192fb952..c431c78d5336b 100644 --- a/src/EditorFeatures/Test/EditAndContinue/EditAndContinueWorkspaceServiceTests.cs +++ b/src/EditorFeatures/Test/EditAndContinue/EditAndContinueWorkspaceServiceTests.cs @@ -3682,7 +3682,7 @@ public async Task UnitTestingHotReloadServiceTest() var hotReload = new UnitTestingHotReloadService(workspace.Services); - await hotReload.StartSessionAsync(solution, CancellationToken.None); + await hotReload.StartSessionAsync(solution, ImmutableArray.Create("Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"), CancellationToken.None); var sessionId = hotReload.GetTestAccessor().SessionId; var session = encService.GetTestAccessor().GetDebuggingSession(sessionId); @@ -3694,13 +3694,13 @@ public async Task UnitTestingHotReloadServiceTest() solution = solution.WithDocumentText(documentIdA, SourceText.From(source2, Encoding.UTF8)); - var result = await hotReload.EmitSolutionUpdateAsync(solution, CancellationToken.None); + var result = await hotReload.EmitSolutionUpdateAsync(solution, true, CancellationToken.None); Assert.Empty(result.diagnostics); Assert.Equal(1, result.updates.Length); solution = solution.WithDocumentText(documentIdA, SourceText.From(source3, Encoding.UTF8)); - result = await hotReload.EmitSolutionUpdateAsync(solution, CancellationToken.None); + result = await hotReload.EmitSolutionUpdateAsync(solution, true, CancellationToken.None); AssertEx.Equal( new[] { "ENC0020: " + string.Format(FeaturesResources.Renaming_0_will_prevent_the_debug_session_from_continuing, FeaturesResources.method) }, result.diagnostics.Select(d => $"{d.Id}: {d.GetMessage()}")); diff --git a/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingHotReloadService.cs b/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingHotReloadService.cs index c4dd30b3a6994..fdc128d2512ab 100644 --- a/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingHotReloadService.cs +++ b/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingHotReloadService.cs @@ -19,7 +19,12 @@ internal sealed class UnitTestingHotReloadService { private sealed class DebuggerService : IManagedEditAndContinueDebuggerService { - public static readonly DebuggerService Instance = new(); + private readonly ImmutableArray _capabilities; + + public DebuggerService(ImmutableArray capabilities) + { + _capabilities = capabilities; + } public Task> GetActiveStatementsAsync(CancellationToken cancellationToken) => Task.FromResult(ImmutableArray.Empty); @@ -27,9 +32,8 @@ public Task> GetActiveStatements public Task GetAvailabilityAsync(Guid module, CancellationToken cancellationToken) => Task.FromResult(new ManagedEditAndContinueAvailability(ManagedEditAndContinueAvailabilityStatus.Available)); - // TODO: get capabilities from the runtime public Task> GetCapabilitiesAsync(CancellationToken cancellationToken) - => Task.FromResult(ImmutableArray.Create("Baseline", "AddDefinitionToExistingType", "NewTypeDefinition")); + => Task.FromResult(_capabilities); public Task PrepareModuleForUpdateAsync(Guid module, CancellationToken cancellationToken) => Task.CompletedTask; @@ -64,24 +68,27 @@ public UnitTestingHotReloadService(HostWorkspaceServices services) /// Starts the watcher. /// /// Solution that represents sources that match the built binaries on disk. + /// Array of capabilities retrieved from the runtime to dictate supported rude edits. /// Cancellation token. - public async Task StartSessionAsync(Solution solution, CancellationToken cancellationToken) + public async Task StartSessionAsync(Solution solution, ImmutableArray capabilities, CancellationToken cancellationToken) { - var newSessionId = await _encService.StartDebuggingSessionAsync(solution, DebuggerService.Instance, captureMatchingDocuments: true, reportDiagnostics: false, cancellationToken).ConfigureAwait(false); + var newSessionId = await _encService.StartDebuggingSessionAsync(solution, new DebuggerService(capabilities), captureMatchingDocuments: true, reportDiagnostics: false, cancellationToken).ConfigureAwait(false); Contract.ThrowIfFalse(_sessionId == default, "Session already started"); _sessionId = newSessionId; } /// - /// Emits updates for all projects that differ between the given snapshot and the one given to the previous successful call or - /// the one passed to for the first invocation. + /// Emits updates for all projects that differ between the given snapshot and the one given to the previous successful call + /// where was `true` or the one passed to + /// for the first invocation. /// /// Solution snapshot. + /// commits changes if true, discards if false /// Cancellation token. /// /// Updates (one for each changed project) and Rude Edit diagnostics. Does not include syntax or semantic diagnostics. /// - public async Task<(ImmutableArray updates, ImmutableArray diagnostics)> EmitSolutionUpdateAsync(Solution solution, CancellationToken cancellationToken) + public async Task<(ImmutableArray updates, ImmutableArray diagnostics)> EmitSolutionUpdateAsync(Solution solution, bool commitUpdates, CancellationToken cancellationToken) { var sessionId = _sessionId; Contract.ThrowIfFalse(sessionId != default, "Session has not started"); @@ -90,7 +97,14 @@ public async Task StartSessionAsync(Solution solution, CancellationToken cancell if (results.ModuleUpdates.Status == ManagedModuleUpdateStatus.Ready) { - _encService.CommitSolutionUpdate(sessionId, out _); + if (commitUpdates) + { + _encService.CommitSolutionUpdate(sessionId, out _); + } + else + { + _encService.DiscardSolutionUpdate(sessionId); + } } var updates = results.ModuleUpdates.Updates.SelectAsArray( diff --git a/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj b/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj index 0bc851e83fe87..ea0e71e2cebfa 100644 --- a/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj +++ b/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj @@ -46,6 +46,7 @@ +