Skip to content

Commit 01a6b9c

Browse files
authored
Revert "Simplify updating the primary workspace without passing in a version" (dotnet#72723)
1 parent 079f6af commit 01a6b9c

File tree

7 files changed

+126
-81
lines changed

7 files changed

+126
-81
lines changed

src/EditorFeatures/Core/Remote/SolutionChecksumUpdater.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public SolutionChecksumUpdater(
6060
listener,
6161
shutdownToken);
6262

63+
// Use an equality comparer here as we will commonly get lots of change notifications that will all be
64+
// associated with the same cancellation token controlling that batch of work. No need to enqueue the same
65+
// token a huge number of times when we only need the single value of it when doing the work.
6366
_synchronizeWorkspaceQueue = new AsyncBatchingWorkQueue(
6467
DelayTimeSpan.NearImmediate,
6568
SynchronizePrimaryWorkspaceAsync,
@@ -139,15 +142,17 @@ private void OnWorkspaceChanged(object? sender, WorkspaceChangeEventArgs e)
139142

140143
private async ValueTask SynchronizePrimaryWorkspaceAsync(CancellationToken cancellationToken)
141144
{
145+
var solution = _workspace.CurrentSolution;
142146
var client = await RemoteHostClient.TryGetClientAsync(_workspace, cancellationToken).ConfigureAwait(false);
143147
if (client == null)
144148
return;
145149

146150
using (Logger.LogBlock(FunctionId.SolutionChecksumUpdater_SynchronizePrimaryWorkspace, cancellationToken))
147151
{
152+
var workspaceVersion = solution.WorkspaceVersion;
148153
await client.TryInvokeAsync<IRemoteAssetSynchronizationService>(
149-
_workspace.CurrentSolution,
150-
(service, solution, cancellationToken) => service.SynchronizePrimaryWorkspaceAsync(solution, cancellationToken),
154+
solution,
155+
(service, solution, cancellationToken) => service.SynchronizePrimaryWorkspaceAsync(solution, workspaceVersion, cancellationToken),
151156
cancellationToken).ConfigureAwait(false);
152157
}
153158
}

src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public async Task TestDesignerAttributes()
137137
// Ensure remote workspace is in sync with normal workspace.
138138
var assetProvider = await GetAssetProviderAsync(workspace, remoteWorkspace, solution);
139139
var solutionChecksum = await solution.CompilationState.GetChecksumAsync(CancellationToken.None);
140-
await remoteWorkspace.UpdatePrimaryBranchSolutionAsync(assetProvider, solutionChecksum, CancellationToken.None);
140+
await remoteWorkspace.UpdatePrimaryBranchSolutionAsync(assetProvider, solutionChecksum, solution.WorkspaceVersion, CancellationToken.None);
141141

142142
var callback = new DesignerAttributeComputerCallback();
143143

@@ -188,7 +188,7 @@ public async Task TestDesignerAttributesUnsupportedLanguage()
188188
// Ensure remote workspace is in sync with normal workspace.
189189
var assetProvider = await GetAssetProviderAsync(workspace, remoteWorkspace, solution);
190190
var solutionChecksum = await solution.CompilationState.GetChecksumAsync(CancellationToken.None);
191-
await remoteWorkspace.UpdatePrimaryBranchSolutionAsync(assetProvider, solutionChecksum, CancellationToken.None);
191+
await remoteWorkspace.UpdatePrimaryBranchSolutionAsync(assetProvider, solutionChecksum, solution.WorkspaceVersion, CancellationToken.None);
192192

193193
var callback = new DesignerAttributeComputerCallback();
194194

@@ -359,8 +359,9 @@ public async Task TestRemoteWorkspaceCircularReferences()
359359
using var remoteWorkspace = new RemoteWorkspace(FeaturesTestCompositions.RemoteHost.GetHostServices());
360360

361361
// this shouldn't throw exception
362-
var solution = await remoteWorkspace.GetTestAccessor().UpdateWorkspaceCurrentSolutionAsync(
363-
remoteWorkspace.GetTestAccessor().CreateSolutionFromInfo(solutionInfo));
362+
var (solution, updated) = await remoteWorkspace.GetTestAccessor().TryUpdateWorkspaceCurrentSolutionAsync(
363+
remoteWorkspace.GetTestAccessor().CreateSolutionFromInfo(solutionInfo), workspaceVersion: 1);
364+
Assert.True(updated);
364365
Assert.NotNull(solution);
365366
}
366367

@@ -827,9 +828,10 @@ private static (Project project, ImmutableArray<Document> documents) GetProjectA
827828

828829
private static async Task UpdatePrimaryWorkspace(RemoteHostClient client, Solution solution)
829830
{
831+
var workspaceVersion = solution.WorkspaceVersion;
830832
await client.TryInvokeAsync<IRemoteAssetSynchronizationService>(
831833
solution,
832-
async (service, solutionInfo, cancellationToken) => await service.SynchronizePrimaryWorkspaceAsync(solutionInfo, cancellationToken),
834+
async (service, solutionInfo, cancellationToken) => await service.SynchronizePrimaryWorkspaceAsync(solutionInfo, workspaceVersion, cancellationToken),
833835
CancellationToken.None);
834836
}
835837

0 commit comments

Comments
 (0)