Skip to content

Commit 8f52554

Browse files
authored
Merge pull request #9624 from drewnoakes/suppress-recursive-factory-detection
Set AsyncLazy.SuppressRecursiveFactoryDetection to true
2 parents a17bdcd + b2606ea commit 8f52554

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public LanguageServiceErrorListProvider(
3636

3737
_isLspPullDiagnosticsEnabled = new AsyncLazy<bool>(
3838
async () => await projectSystemOptions.IsLspPullDiagnosticsEnabledAsync(CancellationToken.None),
39-
joinableTaskContext.Factory);
39+
joinableTaskContext.Factory)
40+
{
41+
SuppressRecursiveFactoryDetection = true
42+
};
4043
}
4144

4245
public void SuspendRefresh()

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Query/PropertyPages/AbstractProjectState.cs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ internal abstract class AbstractProjectState : IProjectState
99
{
1010
protected readonly UnconfiguredProject Project;
1111

12-
private readonly Dictionary<ProjectConfiguration, IPropertyPagesCatalog?> _catalogCache;
13-
private readonly Dictionary<(ProjectConfiguration, string, QueryProjectPropertiesContext), IRule?> _ruleCache;
12+
private readonly Dictionary<ProjectConfiguration, IPropertyPagesCatalog?> _catalogCache = [];
13+
private readonly Dictionary<(ProjectConfiguration, string, QueryProjectPropertiesContext), IRule?> _ruleCache = [];
1414

1515
private readonly AsyncLazy<IImmutableSet<ProjectConfiguration>?> _knownProjectConfigurations;
1616
private readonly AsyncLazy<ProjectConfiguration?> _defaultProjectConfiguration;
@@ -20,10 +20,34 @@ protected AbstractProjectState(UnconfiguredProject project)
2020
Project = project;
2121
JoinableTaskFactory joinableTaskFactory = project.Services.ThreadingPolicy.JoinableTaskFactory;
2222

23-
_knownProjectConfigurations = new AsyncLazy<IImmutableSet<ProjectConfiguration>?>(CreateKnownConfigurationsAsync, joinableTaskFactory);
24-
_defaultProjectConfiguration = new AsyncLazy<ProjectConfiguration?>(CreateDefaultConfigurationAsync, joinableTaskFactory);
25-
_catalogCache = new Dictionary<ProjectConfiguration, IPropertyPagesCatalog?>();
26-
_ruleCache = new Dictionary<(ProjectConfiguration, string, QueryProjectPropertiesContext), IRule?>();
23+
_knownProjectConfigurations = new AsyncLazy<IImmutableSet<ProjectConfiguration>?>(CreateKnownConfigurationsAsync, joinableTaskFactory)
24+
{
25+
SuppressRecursiveFactoryDetection = true
26+
};
27+
28+
_defaultProjectConfiguration = new AsyncLazy<ProjectConfiguration?>(CreateDefaultConfigurationAsync, joinableTaskFactory)
29+
{
30+
SuppressRecursiveFactoryDetection = true
31+
};
32+
33+
async Task<IImmutableSet<ProjectConfiguration>?> CreateKnownConfigurationsAsync()
34+
{
35+
return Project.Services.ProjectConfigurationsService switch
36+
{
37+
IProjectConfigurationsService configurationsService => await configurationsService.GetKnownProjectConfigurationsAsync(),
38+
_ => null
39+
};
40+
}
41+
42+
async Task<ProjectConfiguration?> CreateDefaultConfigurationAsync()
43+
{
44+
return Project.Services.ProjectConfigurationsService switch
45+
{
46+
IProjectConfigurationsService2 configurationsService2 => await configurationsService2.GetSuggestedProjectConfigurationAsync(),
47+
IProjectConfigurationsService configurationsService => configurationsService.SuggestedProjectConfiguration,
48+
_ => null
49+
};
50+
}
2751
}
2852

2953
/// <summary>
@@ -60,32 +84,6 @@ protected AbstractProjectState(UnconfiguredProject project)
6084
/// </summary>
6185
public Task<ProjectConfiguration?> GetSuggestedConfigurationAsync() => _defaultProjectConfiguration.GetValueAsync();
6286

63-
private async Task<ProjectConfiguration?> CreateDefaultConfigurationAsync()
64-
{
65-
if (Project.Services.ProjectConfigurationsService is IProjectConfigurationsService2 configurationsService2)
66-
{
67-
return await configurationsService2.GetSuggestedProjectConfigurationAsync();
68-
}
69-
else if (Project.Services.ProjectConfigurationsService is IProjectConfigurationsService configurationsService)
70-
{
71-
return configurationsService.SuggestedProjectConfiguration;
72-
}
73-
else
74-
{
75-
return null;
76-
}
77-
}
78-
79-
private async Task<IImmutableSet<ProjectConfiguration>?> CreateKnownConfigurationsAsync()
80-
{
81-
if (Project.Services.ProjectConfigurationsService is IProjectConfigurationsService configurationsService)
82-
{
83-
return await configurationsService.GetKnownProjectConfigurationsAsync();
84-
}
85-
86-
return null;
87-
}
88-
8987
/// <summary>
9088
/// Retrieves the set of property pages that apply to the project level for the given <paramref
9189
/// name="projectConfiguration"/>.

src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/PublishItemsOutputGroupProvider.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ internal PublishItemsOutputGroupProvider(
3434
{
3535
_outputGroups = new AsyncLazy<IImmutableSet<IOutputGroup>>(
3636
GetOutputGroupMetadataAsync,
37-
projectThreadingService.JoinableTaskFactory);
37+
projectThreadingService.JoinableTaskFactory)
38+
{
39+
SuppressRecursiveFactoryDetection = true
40+
};
3841

3942
async Task<IImmutableSet<IOutputGroup>> GetOutputGroupMetadataAsync()
4043
{

src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/DebugProfileEnumValuesGenerator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ internal DebugProfileEnumValuesGenerator(
1919
ILaunchSettingsProvider profileProvider,
2020
IProjectThreadingService threadingService)
2121
{
22-
Requires.NotNull(profileProvider);
23-
Requires.NotNull(threadingService);
24-
2522
_listedValues = new AsyncLazy<ICollection<IEnumValue>>(
2623
() =>
2724
{
2825
ILaunchSettings? snapshot = profileProvider.CurrentSnapshot;
2926

3027
ICollection<IEnumValue> values = snapshot is null
31-
? Array.Empty<IEnumValue>()
28+
? []
3229
: GetEnumeratorEnumValues(snapshot);
3330

3431
return Task.FromResult(values);
3532
},
36-
threadingService.JoinableTaskFactory);
33+
threadingService.JoinableTaskFactory)
34+
{
35+
SuppressRecursiveFactoryDetection = true
36+
};
3737
}
3838

3939
public Task<ICollection<IEnumValue>> GetListedValuesAsync()

0 commit comments

Comments
 (0)