Skip to content

Commit ddffabf

Browse files
Use separate async tracker for SG work instad of reusing workspace async tracker
No need to wait to be fully loaded. all we're doing is incrementing numbers, not actually running generators
1 parent e68227e commit ddffabf

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace Roslyn.VisualStudio.Next.UnitTests.Remote
3838
{
3939
[UseExportProvider]
4040
[Trait(Traits.Feature, Traits.Features.RemoteHost)]
41-
public class ServiceHubServicesTests
41+
public sealed class ServiceHubServicesTests
4242
{
4343
private static TestWorkspace CreateWorkspace(Type[] additionalParts = null)
4444
=> new(composition: FeaturesTestCompositions.Features.WithTestHostParts(TestHost.OutOfProcess).AddParts(additionalParts));
@@ -765,10 +765,10 @@ private static DocumentId AddSimpleDocument(TestWorkspace workspace, CallbackGen
765765
return tempDoc.Id;
766766
}
767767

768-
private static IAsynchronousOperationWaiter GetWorkspaceWaiter(TestWorkspace workspace)
768+
private static async Task WaitForSourceGeneratorsAsync(TestWorkspace workspace)
769769
{
770770
var operations = workspace.ExportProvider.GetExportedValue<AsynchronousOperationListenerProvider>();
771-
return operations.GetWaiter(FeatureAttribute.Workspace);
771+
await operations.WaitAllAsync(workspace, [FeatureAttribute.Workspace, FeatureAttribute.SourceGenerators]);
772772
}
773773

774774
[Theory, CombinatorialData]
@@ -810,7 +810,7 @@ internal async Task TestSourceGenerationExecution_MinorVersionChange_NoActualCha
810810
Assert.Equal(1, callCount);
811811

812812
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: false);
813-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
813+
await WaitForSourceGeneratorsAsync(workspace);
814814

815815
solution = workspace.CurrentSolution;
816816
project = solution.Projects.Single();
@@ -866,7 +866,7 @@ internal async Task TestSourceGenerationExecution_MajorVersionChange_NoActualCha
866866

867867
// Because we're forcing regeneration, in both mode we should now see two calls to the generator.
868868
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: true);
869-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
869+
await WaitForSourceGeneratorsAsync(workspace);
870870

871871
solution = workspace.CurrentSolution;
872872
project = solution.Projects.Single();
@@ -913,7 +913,7 @@ internal async Task TestSourceGenerationExecution_FullSolutionChange_Minor(Sourc
913913
var initialSolution = workspace.CurrentSolution;
914914

915915
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: false);
916-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
916+
await WaitForSourceGeneratorsAsync(workspace);
917917

918918
var currentSolution = workspace.CurrentSolution;
919919

@@ -964,7 +964,7 @@ internal async Task TestSourceGenerationExecution_FullSolutionChange_Major(Sourc
964964
var initialSolution = workspace.CurrentSolution;
965965

966966
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: true);
967-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
967+
await WaitForSourceGeneratorsAsync(workspace);
968968

969969
var currentSolution = workspace.CurrentSolution;
970970

@@ -1007,7 +1007,7 @@ internal async Task TestSourceGenerationExecution_FullSolutionChange_MajorAndMin
10071007
// forceRegeneration=true should take precedence.
10081008
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: false);
10091009
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: true);
1010-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
1010+
await WaitForSourceGeneratorsAsync(workspace);
10111011

10121012
var currentSolution = workspace.CurrentSolution;
10131013

@@ -1049,7 +1049,7 @@ internal async Task TestSourceGenerationExecution_ProjectChange_Minor_1(SourceGe
10491049

10501050
// Updating project1 should only impact it.
10511051
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId1, forceRegeneration: false);
1052-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
1052+
await WaitForSourceGeneratorsAsync(workspace);
10531053

10541054
var currentSolution = workspace.CurrentSolution;
10551055

@@ -1102,7 +1102,7 @@ internal async Task TestSourceGenerationExecution_ProjectChange_Minor_2(SourceGe
11021102

11031103
// Updating project1 should regen both projects due to p2p reference.
11041104
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId1, forceRegeneration: false);
1105-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
1105+
await WaitForSourceGeneratorsAsync(workspace);
11061106

11071107
var currentSolution = workspace.CurrentSolution;
11081108

@@ -1155,7 +1155,7 @@ internal async Task TestSourceGenerationExecution_ProjectChange_Minor_3(SourceGe
11551155

11561156
// Updating project2 should regen only it due to project1 having no reference to it.
11571157
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId2, forceRegeneration: false);
1158-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
1158+
await WaitForSourceGeneratorsAsync(workspace);
11591159

11601160
var currentSolution = workspace.CurrentSolution;
11611161

@@ -1210,7 +1210,7 @@ internal async Task TestSourceGenerationExecution_ProjectChange_MinorAndMajor1(S
12101210
// for both as project2 has a ref on project1.
12111211
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId1, forceRegeneration: true);
12121212
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId2, forceRegeneration: false);
1213-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
1213+
await WaitForSourceGeneratorsAsync(workspace);
12141214

12151215
var currentSolution = workspace.CurrentSolution;
12161216

@@ -1255,7 +1255,7 @@ internal async Task TestSourceGenerationExecution_ProjectChange_MinorAndMajor2(S
12551255
// only for project2 as project1 doesn't have a ref on it.
12561256
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId1, forceRegeneration: false);
12571257
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId2, forceRegeneration: true);
1258-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
1258+
await WaitForSourceGeneratorsAsync(workspace);
12591259

12601260
var currentSolution = workspace.CurrentSolution;
12611261

@@ -1298,7 +1298,7 @@ internal async Task TestSourceGenerationExecution_SolutionAndProjectChange_1(Sou
12981298
// Project2 should have a minor update since we only have a solution-minor change.
12991299
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: false);
13001300
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId1, forceRegeneration: true);
1301-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
1301+
await WaitForSourceGeneratorsAsync(workspace);
13021302

13031303
var currentSolution = workspace.CurrentSolution;
13041304

@@ -1341,7 +1341,7 @@ internal async Task TestSourceGenerationExecution_SolutionAndProjectChange_2(Sou
13411341
// Project1 and 2 should have a major update since we have a solution-majorchange.
13421342
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: true);
13431343
workspace.EnqueueUpdateSourceGeneratorVersion(projectId: projectId1, forceRegeneration: false);
1344-
await GetWorkspaceWaiter(workspace).ExpeditedWaitAsync();
1344+
await WaitForSourceGeneratorsAsync(workspace);
13451345

13461346
var currentSolution = workspace.CurrentSolution;
13471347

src/Workspaces/Core/Portable/Workspace/Host/TaskScheduler/IWorkspaceAsynchronousOperationListenerProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ namespace Microsoft.CodeAnalysis.Host;
1212
internal interface IWorkspaceAsynchronousOperationListenerProvider : IWorkspaceService
1313
{
1414
IAsynchronousOperationListener GetListener();
15+
IAsynchronousOperationListener GetListener(string featureName);
1516
}

src/Workspaces/Core/Portable/Workspace/Host/TaskScheduler/WorkspaceAsynchronousOperationListenerProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ internal sealed class WorkspaceAsynchronousOperationListenerProvider(IAsynchrono
1919

2020
public IAsynchronousOperationListener GetListener()
2121
=> _listener;
22+
23+
public IAsynchronousOperationListener GetListener(string featureName)
24+
=> listenerProvider.GetListener(featureName);
2225
}

src/Workspaces/Core/Portable/Workspace/Workspace.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.CodeAnalysis.PooledObjects;
2020
using Microsoft.CodeAnalysis.Remote;
2121
using Microsoft.CodeAnalysis.Shared.Extensions;
22+
using Microsoft.CodeAnalysis.Shared.TestHooks;
2223
using Microsoft.CodeAnalysis.Text;
2324
using Roslyn.Utilities;
2425

@@ -92,7 +93,7 @@ protected Workspace(HostServices host, string? workspaceKind)
9293
TimeSpan.FromMilliseconds(1500),
9394
ProcessUpdateSourceGeneratorRequestAsync,
9495
EqualityComparer<(ProjectId? projectId, bool forceRegeneration)>.Default,
95-
listenerProvider.GetListener(),
96+
listenerProvider.GetListener(FeatureAttribute.SourceGenerators),
9697
_updateSourceGeneratorsQueueTokenSource.Token);
9798
}
9899

src/Workspaces/Core/Portable/Workspace/Workspace_SourceGeneration.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ private async ValueTask ProcessUpdateSourceGeneratorRequestAsync(
4343
return;
4444
}
4545

46-
// Ensure we're fully loaded before rerunning generators.
47-
var workspaceStatusService = this.Services.GetRequiredService<IWorkspaceStatusService>();
48-
await workspaceStatusService.WaitUntilFullyLoadedAsync(cancellationToken).ConfigureAwait(false);
49-
5046
await this.SetCurrentSolutionAsync(
5147
useAsync: true,
5248
oldSolution =>

0 commit comments

Comments
 (0)