Skip to content
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 @@ -132,13 +132,11 @@ public RazorCodeDocument ProcessDesignTime(
return ProcessCore(codeDocument, cancellationToken);
}

internal RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem, bool designTime)
internal RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem)
{
ArgHelper.ThrowIfNull(projectItem);

return designTime
? CreateCodeDocumentDesignTimeCore(projectItem)
: CreateCodeDocumentCore(projectItem);
return CreateCodeDocumentCore(projectItem);
}

internal RazorCodeDocument CreateCodeDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<EmbeddedResource Update="SourceGenerators\Diagnostics\*.resx" Namespace="Microsoft.NET.Sdk.Razor.SourceGenerators.Diagnostics" />
</ItemGroup>

<ItemGroup>
<None Update="RazorSourceGenerator.razorencconfig" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<!-- SDK: src/RazorSdk/Tool/Microsoft.NET.Sdk.Razor.Tool.csproj -->
<InternalsVisibleTo Include="rzc" Key="$(RazorKey)" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,59 +52,6 @@ internal static IncrementalValueProvider<TSource> ReportDiagnostics<TSource>(thi

return source.Select((pair, ct) => pair.Item1!);
}

internal static IncrementalValuesProvider<T> EmptyOrCachedWhen<T>(this IncrementalValuesProvider<T> provider, IncrementalValueProvider<bool> checkProvider, bool check)
{
// This code is a little hard to understand:
// Basically you can think about this provider having two states: 'on' and 'off'.
// When the checkProvider equals the check value, the provider is 'on'
// When in the 'on' state, data flows through it as usual.
// When in the 'off' state you get either: an empty provider, if it has never been 'on' before, or the last 'on' data, but all cached.

// First we create a check provider that 'latches'. That is, once it has been flipped into the 'on' state, it never goes back to 'off'
var latchedCheckProvider = checkProvider.WithLambdaComparer((old, @new) => IsOn(old) || old == @new);

// Next we filter on the latched provider. When the provider is off we return an empty array, when it's on we allow data to flow through.
var dataProvider = provider.Combine(latchedCheckProvider)
.Where(pair => IsOn(pair.Right))
.Select((pair, _) => pair.Left);

// Now, we compare against the real value of the check provider. If the real provider is 'on' we allow the data through. When the provider is
// 'off' we set all the data to cached. This allows the caches to remain full, but still disable any further downstream processing.
var realProvider = dataProvider.Combine(checkProvider)

// We have to group and ungroup the data before comparing to ensure that we correctly handle added and removed cases which would otherwise
// not get compared and would be processed downstream
.Collect()

// When the real value is 'on', always say the data is modified. When the value is 'off' say it's cached
.WithLambdaComparer((old, @new) => !IsOn(@new.FirstOrDefault().Right))

// When 'on' the data will be re-evaluated item-wise here, ensuring only things that have actually changed will be marked as such.
// When 'off' the previous data was cached so nothing downstream runs.
.SelectMany((arr, _) => arr)
.Select((pair, _) => pair.Left);

return realProvider;

bool IsOn(bool value) => value != check;
}

/// <summary>
/// Ensures that <paramref name="input"/> reports as up to date if <paramref name="suppressionCheck"/> returns <see langword="true"/>.
/// </summary>
internal static IncrementalValueProvider<(T, bool)> SuppressIfNeeded<T>(this IncrementalValueProvider<T> input, IncrementalValueProvider<bool> suppressionCheck)
{
return input
.Combine(suppressionCheck)
// when the suppression check is true, we always say its up to date. Otherwise we perform the default comparison on the item itself.
.WithLambdaComparer((old, @new) => @new.Right || EqualityComparer<T>.Default.Equals(old.Left, @new.Left));
}

internal static IncrementalValueProvider<bool> CheckGlobalFlagSet(this IncrementalValueProvider<AnalyzerConfigOptionsProvider> optionsProvider, string flagName)
{
return optionsProvider.Select((provider, _) => provider.GlobalOptions.TryGetValue($"build_property.{flagName}", out var flagValue) && flagValue == "true");
}
}

internal sealed class LambdaComparer<T> : IEqualityComparer<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ namespace Microsoft.NET.Sdk.Razor.SourceGenerators
{
public partial class RazorSourceGenerator
{
private (RazorSourceGenerationOptions?, Diagnostic?) ComputeRazorSourceGeneratorOptions((((AnalyzerConfigOptionsProvider, ParseOptions), ImmutableArray<MetadataReference>), bool) pair, CancellationToken ct)
private (RazorSourceGenerationOptions?, Diagnostic?) ComputeRazorSourceGeneratorOptions(((AnalyzerConfigOptionsProvider, ParseOptions), ImmutableArray<MetadataReference>) pair, CancellationToken ct)
{
var (((options, parseOptions), references), isSuppressed) = pair;
var ((options, parseOptions), references) = pair;
var globalOptions = options.GlobalOptions;

if (isSuppressed)
{
return default;
}

Log.ComputeRazorSourceGeneratorOptions();

globalOptions.TryGetValue("build_property.RazorConfiguration", out var configurationName);
Expand Down
Loading