public void Initialize(IncrementalGeneratorInitializationContext context)
        {
            context.RegisterPostInitializationOutput(PostInitializationCallback);

            IncrementalValueProvider <ImmutableArray <MethodDeclarationSyntax> > syntaxProvider = context.SyntaxProvider
                                                                                                  .CreateSyntaxProvider(SyntaxProviderPredicate, SyntaxProviderTransform)
                                                                                                  .Where(static method => method is not null)
예제 #2
0
        public void Initialize(IncrementalGeneratorInitializationContext context)
        {
            // Contains one entry per regex method, either the generated code for that regex method,
            // a diagnostic to fail with, or null if no action should be taken for that regex.
            IncrementalValueProvider<ImmutableArray<object?>> codeOrDiagnostics =
                context.SyntaxProvider

                // Find all MethodDeclarationSyntax nodes attributed with RegexGenerator
                .CreateSyntaxProvider(static (s, _) => IsSyntaxTargetForGeneration(s), static (ctx, _) => GetSemanticTargetForGeneration(ctx))
예제 #3
0
 public void Initialize(IncrementalGeneratorInitializationContext context)
 {
     // To avoid invalidating the generator's output when anything from the compilation
     // changes, we will extract from it the only thing we care about: whether unsafe
     // code is allowed.
     IncrementalValueProvider <bool> allowUnsafeProvider =
         context.CompilationProvider
         .Select((x, _) => x.Options is CSharpCompilationOptions {
         AllowUnsafe: true
     });
예제 #4
0
        public void Initialize(IncrementalGeneratorInitializationContext context)
        {
            // Produces one entry per generated regex.  This may be:
            // - Diagnostic in the case of a failure that should end the compilation
            // - (RegexMethod regexMethod, string runnerFactoryImplementation, Dictionary<string, string[]> requiredHelpers) in the case of valid regex
            // - (RegexMethod regexMethod, string reason, Diagnostic diagnostic) in the case of a limited-support regex
            IncrementalValueProvider <ImmutableArray <object> > codeOrDiagnostics =
                context.SyntaxProvider

                // Find all MethodDeclarationSyntax nodes attributed with RegexGenerator and gather the required information.
                .CreateSyntaxProvider(IsSyntaxTargetForGeneration, GetSemanticTargetForGeneration)
                .Where(static m => m is not null)
예제 #5
0
        internal static IncrementalValueProvider <T> WithLambdaComparer <T>(this IncrementalValueProvider <T> source, Func <T, T, bool> equal, Func <T, int> getHashCode)
        {
            var comparer = new LambdaComparer <T>(equal, getHashCode);

            return(source.WithComparer(comparer));
        }
예제 #6
0
 /// <inheritdoc/>
 public void Initialize(IncrementalGeneratorInitializationContext context)
 {
     // Check whether [SkipLocalsInit] can be used
     IncrementalValueProvider <bool> canUseSkipLocalsInit =
         context.CompilationProvider
         .Select(static (compilation, token) =>
 /// <summary>
 /// Adds a comparer that will force the provider to be considered as cached if the razor options call for suppression
 /// </summary>
 internal static IncrementalValuesProvider <T> AsCachedIfSuppressed <T>(this IncrementalValuesProvider <T> provider, IncrementalValueProvider <bool> isSuppressedProvider)
     where T : notnull
 {
     return(provider.Combine(isSuppressedProvider).WithComparer(new RazorSourceGeneratorComparer <T>()).Select((pair, _) => pair.Left));
 }
예제 #8
0
 public static IncrementalValueProvider<(ApplicationConfig? ApplicationConfig, Diagnostic? Diagnostic)> ReadApplicationConfig(IncrementalValueProvider<AnalyzerConfigOptionsProvider> configOptionsProvider)
     => configOptionsProvider.Select(