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

Simplify ForAttributeWithMetadataName #72979

Merged
merged 2 commits into from
Apr 12, 2024
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ public partial struct SyntaxValueProvider

// Create a provider that provides (and updates) the global aliases for any particular file when it is edited.
var individualFileGlobalAliasesProvider = syntaxTreesProvider
.Where((info, _) => info.Info.HasFlag(SourceGeneratorSyntaxTreeInfo.ContainsGlobalAliases))
.Where(static (info, _) => info.Info.HasFlag(SourceGeneratorSyntaxTreeInfo.ContainsGlobalAliases))
.Select((info, cancellationToken) => getGlobalAliasesInCompilationUnit(syntaxHelper, info.Tree.GetRoot(cancellationToken)))
.WithTrackingName("individualFileGlobalAliases_ForAttribute");

// Create an aggregated view of all global aliases across all files. This should only update when an individual
// file changes its global aliases or a file is added / removed from the compilation
var collectedGlobalAliasesProvider = individualFileGlobalAliasesProvider
.Collect()
.WithComparer(ImmutableArrayValueComparer<GlobalAliases>.Instance)
.WithTrackingName("collectedGlobalAliases_ForAttribute");

var allUpGlobalAliasesProvider = collectedGlobalAliasesProvider
Expand All @@ -95,19 +94,19 @@ public partial struct SyntaxValueProvider

allUpGlobalAliasesProvider = allUpGlobalAliasesProvider
.Combine(compilationGlobalAliases)
.Select((tuple, _) => GlobalAliases.Concat(tuple.Left, tuple.Right))
.Select(static (tuple, _) => GlobalAliases.Concat(tuple.Left, tuple.Right))
.WithTrackingName("allUpIncludingCompilationGlobalAliases_ForAttribute");

// Combine the two providers so that we reanalyze every file if the global aliases change, or we reanalyze a
// particular file when it's compilation unit changes.
var syntaxTreeAndGlobalAliasesProvider = syntaxTreesProvider
.Where((info, _) => info.Info.HasFlag(SourceGeneratorSyntaxTreeInfo.ContainsAttributeList))
.Where(static (info, _) => info.Info.HasFlag(SourceGeneratorSyntaxTreeInfo.ContainsAttributeList))
.Combine(allUpGlobalAliasesProvider)
.WithTrackingName("compilationUnitAndGlobalAliases_ForAttribute");

return syntaxTreeAndGlobalAliasesProvider
.Select((tuple, c) => (tuple.Left.Tree, GetMatchingNodes(syntaxHelper, tuple.Right, tuple.Left.Tree, simpleName, predicate, c)))
.Where(tuple => tuple.Item2.Length > 0)
.Where(static tuple => tuple.Item2.Length > 0)
.WithTrackingName("result_ForAttributeInternal");

static GlobalAliases getGlobalAliasesInCompilationUnit(
Expand Down
Loading