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
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ internal sealed class TrackingSession
private readonly Workspace _workspace;
private readonly CancellationTokenSource _cancellationSource = new();
private readonly IActiveStatementSpanFactory _spanProvider;
private readonly ICompileTimeSolutionProvider _compileTimeSolutionProvider;
private readonly WorkspaceEventRegistration _documentOpenedHandlerDisposer;
private readonly WorkspaceEventRegistration _documentClosedHandlerDisposer;

Expand All @@ -121,7 +120,6 @@ public TrackingSession(Workspace workspace, IActiveStatementSpanFactory spanProv
{
_workspace = workspace;
_spanProvider = spanProvider;
_compileTimeSolutionProvider = workspace.Services.GetRequiredService<ICompileTimeSolutionProvider>();

_documentOpenedHandlerDisposer = _workspace.RegisterDocumentOpenedHandler(DocumentOpened);
_documentClosedHandlerDisposer = _workspace.RegisterDocumentClosedHandler(DocumentClosed);
Expand Down Expand Up @@ -158,26 +156,23 @@ private void DocumentClosed(DocumentEventArgs e)
private void DocumentOpened(DocumentEventArgs e)
=> _ = TrackActiveSpansAsync(e.Document);

private async Task TrackActiveSpansAsync(Document designTimeDocument)
private async Task TrackActiveSpansAsync(Document document)
{
try
{
var cancellationToken = _cancellationSource.Token;

if (!designTimeDocument.DocumentState.SupportsEditAndContinue())
if (!document.DocumentState.SupportsEditAndContinue())
{
return;
}

var compileTimeSolution = _compileTimeSolutionProvider.GetCompileTimeSolution(designTimeDocument.Project.Solution);
var compileTimeDocument = await compileTimeSolution.GetDocumentAsync(designTimeDocument.Id, includeSourceGenerated: true, cancellationToken).ConfigureAwait(false);

if (compileTimeDocument == null || !TryGetSnapshot(compileTimeDocument, out var snapshot))
if (!TryGetSnapshot(document, out var snapshot))
{
return;
}

_ = await GetAdjustedTrackingSpansAsync(compileTimeDocument, snapshot, cancellationToken).ConfigureAwait(false);
_ = await GetAdjustedTrackingSpansAsync(document, snapshot, cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public NoSessionException()
private bool _disabled;
private RemoteDebuggingSessionProxy? _debuggingSession;

private Solution? _pendingUpdatedDesignTimeSolution;
private Solution? _committedDesignTimeSolution;
private Solution? _pendingUpdatedSolution;
private Solution? _committedSolution;

public event Action<Solution>? SolutionCommitted;

Expand All @@ -72,12 +72,9 @@ public void SetFileLoggingDirectory(string? logDirectory)
private SolutionServices Services
=> workspaceProvider.Value.Workspace.Services.SolutionServices;

private Solution GetCurrentDesignTimeSolution()
private Solution GetCurrentSolution()
=> workspaceProvider.Value.Workspace.CurrentSolution;

private Solution GetCurrentCompileTimeSolution(Solution currentDesignTimeSolution)
=> Services.GetRequiredService<ICompileTimeSolutionProvider>().GetCompileTimeSolution(currentDesignTimeSolution);

private RemoteDebuggingSessionProxy GetDebuggingSession()
=> _debuggingSession ?? throw new NoSessionException();

Expand Down Expand Up @@ -114,16 +111,15 @@ public async ValueTask StartSessionAsync(CancellationToken cancellationToken)
// so that we don't miss any pertinent workspace update events.
sourceTextProvider.Activate();

var currentSolution = GetCurrentDesignTimeSolution();
_committedDesignTimeSolution = currentSolution;
var solution = GetCurrentCompileTimeSolution(currentSolution);
var currentSolution = GetCurrentSolution();
_committedSolution = currentSolution;

sourceTextProvider.SetBaseline(currentSolution);

var proxy = new RemoteEditAndContinueServiceProxy(Services);

_debuggingSession = await proxy.StartDebuggingSessionAsync(
solution,
currentSolution,
new ManagedHotReloadServiceBridge(debuggerService.Value),
sourceTextProvider,
reportDiagnostics: true,
Expand Down Expand Up @@ -155,7 +151,7 @@ private async ValueTask BreakStateOrCapabilitiesChangedAsync(bool? inBreakState,
try
{
var session = GetDebuggingSession();
var solution = (inBreakState == true) ? GetCurrentCompileTimeSolution(GetCurrentDesignTimeSolution()) : null;
var solution = (inBreakState == true) ? GetCurrentSolution() : null;

await session.BreakStateOrCapabilitiesChangedAsync(inBreakState, cancellationToken).ConfigureAwait(false);

Expand Down Expand Up @@ -191,18 +187,18 @@ public async ValueTask CommitUpdatesAsync(CancellationToken cancellationToken)
return;
}

var committedDesignTimeSolution = Interlocked.Exchange(ref _pendingUpdatedDesignTimeSolution, null);
Contract.ThrowIfNull(committedDesignTimeSolution);
var committedSolution = Interlocked.Exchange(ref _pendingUpdatedSolution, null);
Contract.ThrowIfNull(committedSolution);

try
{
SolutionCommitted?.Invoke(committedDesignTimeSolution);
SolutionCommitted?.Invoke(committedSolution);
}
catch (Exception e) when (FatalError.ReportAndCatch(e))
{
}

_committedDesignTimeSolution = committedDesignTimeSolution;
_committedSolution = committedSolution;

try
{
Expand All @@ -222,7 +218,7 @@ public async ValueTask DiscardUpdatesAsync(CancellationToken cancellationToken)
return;
}

Contract.ThrowIfNull(Interlocked.Exchange(ref _pendingUpdatedDesignTimeSolution, null));
Contract.ThrowIfNull(Interlocked.Exchange(ref _pendingUpdatedSolution, null));

try
{
Expand Down Expand Up @@ -258,8 +254,8 @@ public async ValueTask EndSessionAsync(CancellationToken cancellationToken)

sourceTextProvider.Deactivate();
_debuggingSession = null;
_committedDesignTimeSolution = null;
_pendingUpdatedDesignTimeSolution = null;
_committedSolution = null;
_pendingUpdatedSolution = null;
}

private ActiveStatementSpanProvider GetActiveStatementSpanProvider(Solution solution)
Expand Down Expand Up @@ -290,9 +286,9 @@ public async ValueTask<bool> HasChangesAsync(string? sourceFilePath, Cancellatio
return false;
}

Contract.ThrowIfNull(_committedDesignTimeSolution);
var oldSolution = _committedDesignTimeSolution;
var newSolution = GetCurrentDesignTimeSolution();
Contract.ThrowIfNull(_committedSolution);
var oldSolution = _committedSolution;
var newSolution = GetCurrentSolution();

return (sourceFilePath != null)
? await EditSession.HasChangesAsync(oldSolution, newSolution, sourceFilePath, cancellationToken).ConfigureAwait(false)
Expand Down Expand Up @@ -326,8 +322,7 @@ public async ValueTask<ManagedHotReloadUpdates> GetUpdatesAsync(ImmutableArray<R
return new ManagedHotReloadUpdates([], []);
}

var designTimeSolution = GetCurrentDesignTimeSolution();
var solution = GetCurrentCompileTimeSolution(designTimeSolution);
var solution = GetCurrentSolution();
var activeStatementSpanProvider = GetActiveStatementSpanProvider(solution);
var runningProjectOptions = runningProjects.ToRunningProjectOptions(solution, static info => (info.ProjectInstanceId.ProjectFilePath, info.ProjectInstanceId.TargetFramework, info.RestartAutomatically));

Expand All @@ -338,13 +333,13 @@ public async ValueTask<ManagedHotReloadUpdates> GetUpdatesAsync(ImmutableArray<R
case ModuleUpdateStatus.Ready:
// The debugger will call Commit/Discard on the solution
// based on whether the updates will be applied successfully or not.
_pendingUpdatedDesignTimeSolution = designTimeSolution;
_pendingUpdatedSolution = solution;
break;

case ModuleUpdateStatus.None:
// No significant changes have been made.
// Commit the solution to apply any changes in comments that do not generate updates.
_committedDesignTimeSolution = designTimeSolution;
_committedSolution = solution;
break;
}

Expand Down
10 changes: 0 additions & 10 deletions src/Features/Core/Portable/Options/LegacyRazorOptions.cs

This file was deleted.

Loading
Loading