Skip to content

Commit 3f72a9f

Browse files
committed
Allow getting sponsors options for non-incremental generator
1 parent fb82cf3 commit 3f72a9f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

samples/dotnet/SponsorLink/SponsorLink.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ public static IncrementalValueProvider<StatusOptions> GetStatusOptions(this Incr
107107
=> context.GetSponsorAdditionalFiles().Combine(context.AnalyzerConfigOptionsProvider)
108108
.Select((source, _) => new StatusOptions(source.Left, source.Right.GlobalOptions));
109109

110+
/// <summary>
111+
/// Gets the status options for use within a source generator, to avoid depending on
112+
/// analyzer runs. Used in combination with <see cref="DiagnosticsManager.GetOrSetStatus(StatusOptions)"/>.
113+
/// </summary>
114+
public static StatusOptions GetStatusOptions(this GeneratorExecutionContext context)
115+
=> new StatusOptions(
116+
context.AdditionalFiles.Where(x => x.IsSponsorManifest(context.AnalyzerConfigOptions) || x.IsSponsorableAnalyzer(context.AnalyzerConfigOptions)).ToImmutableArray(),
117+
context.AnalyzerConfigOptions.GlobalOptions);
118+
110119
static bool IsSponsorManifest(this AdditionalText text, AnalyzerConfigOptionsProvider provider)
111120
=> provider.GetOptions(text).TryGetValue("build_metadata.SponsorManifest.ItemType", out var itemType) &&
112121
itemType == "SponsorManifest" &&

0 commit comments

Comments
 (0)