Skip to content

Commit

Permalink
Allow getting sponsors options for non-incremental generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Dec 3, 2024
1 parent fb82cf3 commit 3f72a9f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samples/dotnet/SponsorLink/SponsorLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ public static IncrementalValueProvider<StatusOptions> GetStatusOptions(this Incr
=> context.GetSponsorAdditionalFiles().Combine(context.AnalyzerConfigOptionsProvider)
.Select((source, _) => new StatusOptions(source.Left, source.Right.GlobalOptions));

/// <summary>
/// Gets the status options for use within a source generator, to avoid depending on
/// analyzer runs. Used in combination with <see cref="DiagnosticsManager.GetOrSetStatus(StatusOptions)"/>.
/// </summary>
public static StatusOptions GetStatusOptions(this GeneratorExecutionContext context)
=> new StatusOptions(
context.AdditionalFiles.Where(x => x.IsSponsorManifest(context.AnalyzerConfigOptions) || x.IsSponsorableAnalyzer(context.AnalyzerConfigOptions)).ToImmutableArray(),
context.AnalyzerConfigOptions.GlobalOptions);

static bool IsSponsorManifest(this AdditionalText text, AnalyzerConfigOptionsProvider provider)
=> provider.GetOptions(text).TryGetValue("build_metadata.SponsorManifest.ItemType", out var itemType) &&
itemType == "SponsorManifest" &&
Expand Down

0 comments on commit 3f72a9f

Please sign in to comment.