Skip to content
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
16 changes: 8 additions & 8 deletions src/Features/ExternalAccess/HotReload/Api/HotReloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Contracts.EditAndContinue;
Expand All @@ -14,7 +12,7 @@

namespace Microsoft.CodeAnalysis.ExternalAccess.HotReload.Api;

internal sealed class HotReloadService(SolutionServices services, Func<ValueTask<ImmutableArray<string>>> capabilitiesProvider)
internal sealed class HotReloadService
{
private sealed class DebuggerService(Func<ValueTask<ImmutableArray<string>>> capabilitiesProvider) : IManagedHotReloadService
{
Expand Down Expand Up @@ -131,14 +129,16 @@ public readonly struct Updates
private static readonly ActiveStatementSpanProvider s_solutionActiveStatementSpanProvider =
(_, _, _) => ValueTask.FromResult(ImmutableArray<ActiveStatementSpan>.Empty);

private readonly IEditAndContinueService _encService = services.GetRequiredService<IEditAndContinueWorkspaceService>().Service;

private readonly IEditAndContinueService _encService;
private readonly Func<ValueTask<ImmutableArray<string>>> _capabilitiesProvider;
private DebuggingSessionId _sessionId;

public HotReloadService(HostWorkspaceServices services, ImmutableArray<string> capabilities)
: this(services.SolutionServices, () => ValueTask.FromResult(capabilities))
public HotReloadService(SolutionServices services, Func<ValueTask<ImmutableArray<string>>> capabilitiesProvider)
{
AbstractEditAndContinueAnalyzer.EnableProjectLevelAnalysis = true;

_capabilitiesProvider = capabilitiesProvider;
_encService = services.GetRequiredService<IEditAndContinueWorkspaceService>().Service;
}

private DebuggingSessionId GetDebuggingSession()
Expand All @@ -160,7 +160,7 @@ public async Task StartSessionAsync(Solution solution, CancellationToken cancell

var newSessionId = _encService.StartDebuggingSession(
solution,
new DebuggerService(capabilitiesProvider),
new DebuggerService(_capabilitiesProvider),
NullPdbMatchingSourceTextProvider.Instance,
reportDiagnostics: false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ private static Task<SourceText> GetCommittedDocumentTextAsync(HotReloadService s
.GetRequiredDocument(documentId)
.GetTextAsync();

private static HotReloadService CreateHotReloadService(Workspace workspace, ImmutableArray<string> capabilities)
=> new(workspace.Services.SolutionServices, () => ValueTask.FromResult(capabilities));

[Fact]
public async Task Test()
{
Expand All @@ -53,7 +56,7 @@ public async Task Test()

EmitLibrary(solution.GetRequiredProject(projectId));

var hotReload = new HotReloadService(workspace.Services, ["Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"]);
var hotReload = CreateHotReloadService(workspace, ["Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"]);

await hotReload.StartSessionAsync(solution, CancellationToken.None);

Expand Down Expand Up @@ -188,7 +191,7 @@ public async Task SourceGeneratorFailure()
var generatorDiagnostics = await solution.CompilationState.GetSourceGeneratorDiagnosticsAsync(project.State, CancellationToken.None);
Assert.Empty(generatorDiagnostics);

var hotReload = new HotReloadService(workspace.Services, ["Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"]);
var hotReload = CreateHotReloadService(workspace, ["Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"]);

await hotReload.StartSessionAsync(solution, CancellationToken.None);

Expand Down Expand Up @@ -232,7 +235,7 @@ public async Task AdditionalFile()

EmitLibrary(solution.GetRequiredProject(projectId));

var hotReload = new HotReloadService(workspace.Services, ["Baseline", "AddDefinitionToExistingType"]);
var hotReload = CreateHotReloadService(workspace, ["Baseline", "AddDefinitionToExistingType"]);

await hotReload.StartSessionAsync(solution, CancellationToken.None);

Expand Down Expand Up @@ -278,7 +281,7 @@ public async Task AnalyzerConfigFile()

EmitLibrary(solution.GetRequiredProject(projectId));

var hotReload = new HotReloadService(workspace.Services, ["Baseline", "AddDefinitionToExistingType"]);
var hotReload = CreateHotReloadService(workspace, ["Baseline", "AddDefinitionToExistingType"]);

await hotReload.StartSessionAsync(solution, CancellationToken.None);

Expand Down Expand Up @@ -318,7 +321,7 @@ public async Task StaleSource(string language)

sourceFileA.WriteAllText(source2, Encoding.UTF8);

var hotReload = new HotReloadService(workspace.Services, ["Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"]);
var hotReload = CreateHotReloadService(workspace, ["Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"]);

// loads source text V2 from disk:
await hotReload.StartSessionAsync(solution, CancellationToken.None);
Expand Down Expand Up @@ -375,7 +378,7 @@ public async Task StaleSource_AdditionalFile()

additionalFileA.WriteAllText(source2);

var hotReload = new HotReloadService(workspace.Services, ["Baseline", "AddDefinitionToExistingType"]);
var hotReload = CreateHotReloadService(workspace, ["Baseline", "AddDefinitionToExistingType"]);

// V2 of the text is loaded from disk:
await hotReload.StartSessionAsync(solution, CancellationToken.None);
Expand Down Expand Up @@ -411,7 +414,7 @@ public async Task HydrateDocumentsAsync(string language)

sourceFileA.WriteAllText("source", Encoding.UTF8);

var hotReload = new HotReloadService(workspace.Services, ["Baseline"]);
var hotReload = CreateHotReloadService(workspace, ["Baseline"]);

await hotReload.StartSessionAsync(solution, CancellationToken.None);

Expand Down
Loading