Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set AsyncLazy.SuppressRecursiveFactoryDetection to true #9624

Merged
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 @@ -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 = [];
drewnoakes marked this conversation as resolved.
Show resolved Hide resolved
private readonly Dictionary<(ProjectConfiguration, string, QueryProjectPropertiesContext), IRule?> _ruleCache = [];
drewnoakes marked this conversation as resolved.
Show resolved Hide resolved

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
Loading