Skip to content

Commit

Permalink
Merge pull request #9624 from drewnoakes/suppress-recursive-factory-d…
Browse files Browse the repository at this point in the history
…etection

Set AsyncLazy.SuppressRecursiveFactoryDetection to true
  • Loading branch information
drewnoakes authored Dec 18, 2024
2 parents a17bdcd + b2606ea commit 8f52554
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public LanguageServiceErrorListProvider(

_isLspPullDiagnosticsEnabled = new AsyncLazy<bool>(
async () => await projectSystemOptions.IsLspPullDiagnosticsEnabledAsync(CancellationToken.None),
joinableTaskContext.Factory);
joinableTaskContext.Factory)
{
SuppressRecursiveFactoryDetection = true
};
}

public void SuspendRefresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ internal abstract class AbstractProjectState : IProjectState
{
protected readonly UnconfiguredProject Project;

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

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

_knownProjectConfigurations = new AsyncLazy<IImmutableSet<ProjectConfiguration>?>(CreateKnownConfigurationsAsync, joinableTaskFactory);
_defaultProjectConfiguration = new AsyncLazy<ProjectConfiguration?>(CreateDefaultConfigurationAsync, joinableTaskFactory);
_catalogCache = new Dictionary<ProjectConfiguration, IPropertyPagesCatalog?>();
_ruleCache = new Dictionary<(ProjectConfiguration, string, QueryProjectPropertiesContext), IRule?>();
_knownProjectConfigurations = new AsyncLazy<IImmutableSet<ProjectConfiguration>?>(CreateKnownConfigurationsAsync, joinableTaskFactory)
{
SuppressRecursiveFactoryDetection = true
};

_defaultProjectConfiguration = new AsyncLazy<ProjectConfiguration?>(CreateDefaultConfigurationAsync, joinableTaskFactory)
{
SuppressRecursiveFactoryDetection = true
};

async Task<IImmutableSet<ProjectConfiguration>?> CreateKnownConfigurationsAsync()
{
return Project.Services.ProjectConfigurationsService switch
{
IProjectConfigurationsService configurationsService => await configurationsService.GetKnownProjectConfigurationsAsync(),
_ => null
};
}

async Task<ProjectConfiguration?> CreateDefaultConfigurationAsync()
{
return Project.Services.ProjectConfigurationsService switch
{
IProjectConfigurationsService2 configurationsService2 => await configurationsService2.GetSuggestedProjectConfigurationAsync(),
IProjectConfigurationsService configurationsService => configurationsService.SuggestedProjectConfiguration,
_ => null
};
}
}

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

private async Task<ProjectConfiguration?> CreateDefaultConfigurationAsync()
{
if (Project.Services.ProjectConfigurationsService is IProjectConfigurationsService2 configurationsService2)
{
return await configurationsService2.GetSuggestedProjectConfigurationAsync();
}
else if (Project.Services.ProjectConfigurationsService is IProjectConfigurationsService configurationsService)
{
return configurationsService.SuggestedProjectConfiguration;
}
else
{
return null;
}
}

private async Task<IImmutableSet<ProjectConfiguration>?> CreateKnownConfigurationsAsync()
{
if (Project.Services.ProjectConfigurationsService is IProjectConfigurationsService configurationsService)
{
return await configurationsService.GetKnownProjectConfigurationsAsync();
}

return null;
}

/// <summary>
/// Retrieves the set of property pages that apply to the project level for the given <paramref
/// name="projectConfiguration"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ internal PublishItemsOutputGroupProvider(
{
_outputGroups = new AsyncLazy<IImmutableSet<IOutputGroup>>(
GetOutputGroupMetadataAsync,
projectThreadingService.JoinableTaskFactory);
projectThreadingService.JoinableTaskFactory)
{
SuppressRecursiveFactoryDetection = true
};

async Task<IImmutableSet<IOutputGroup>> GetOutputGroupMetadataAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ internal DebugProfileEnumValuesGenerator(
ILaunchSettingsProvider profileProvider,
IProjectThreadingService threadingService)
{
Requires.NotNull(profileProvider);
Requires.NotNull(threadingService);

_listedValues = new AsyncLazy<ICollection<IEnumValue>>(
() =>
{
ILaunchSettings? snapshot = profileProvider.CurrentSnapshot;

ICollection<IEnumValue> values = snapshot is null
? Array.Empty<IEnumValue>()
? []
: GetEnumeratorEnumValues(snapshot);

return Task.FromResult(values);
},
threadingService.JoinableTaskFactory);
threadingService.JoinableTaskFactory)
{
SuppressRecursiveFactoryDetection = true
};
}

public Task<ICollection<IEnumValue>> GetListedValuesAsync()
Expand Down

0 comments on commit 8f52554

Please sign in to comment.