Example #1
0
 public IncrementalExecutionContext(DriverStateTable.Builder?tableBuilder, GeneratorRunStateTable.Builder generatorRunStateBuilder, AdditionalSourcesCollection sources)
 {
     TableBuilder             = tableBuilder;
     GeneratorRunStateBuilder = generatorRunStateBuilder;
     Sources     = sources;
     Diagnostics = DiagnosticBag.GetInstance();
 }
 internal SourceGeneratorContext(Compilation compilation, ImmutableArray <AdditionalText> additionalTexts, ISyntaxReceiver?syntaxReceiver, DiagnosticBag diagnostics, CancellationToken cancellationToken = default)
 {
     Compilation       = compilation;
     AdditionalFiles   = additionalTexts;
     SyntaxReceiver    = syntaxReceiver;
     CancellationToken = cancellationToken;
     AdditionalSources = new AdditionalSourcesCollection();
     _diagnostics      = diagnostics;
 }
Example #3
0
 internal SourceGeneratorContext(Compilation compilation, ImmutableArray <AdditionalText> additionalTexts, AnalyzerConfigOptionsProvider optionsProvider, ISyntaxReceiver?syntaxReceiver, CancellationToken cancellationToken = default)
 {
     Compilation           = compilation;
     AdditionalFiles       = additionalTexts;
     AnalyzerConfigOptions = optionsProvider;
     SyntaxReceiver        = syntaxReceiver;
     CancellationToken     = cancellationToken;
     _additionalSources    = new AdditionalSourcesCollection();
     _diagnostics          = new DiagnosticBag();
 }
Example #4
0
 internal GeneratorExecutionContext(Compilation compilation, ParseOptions parseOptions, ImmutableArray <AdditionalText> additionalTexts, AnalyzerConfigOptionsProvider optionsProvider, ISyntaxContextReceiver?syntaxReceiver, AdditionalSourcesCollection additionalSources, CancellationToken cancellationToken = default)
 {
     Compilation           = compilation;
     ParseOptions          = parseOptions;
     AdditionalFiles       = additionalTexts;
     AnalyzerConfigOptions = optionsProvider;
     SyntaxReceiver        = (syntaxReceiver as SyntaxContextReceiverAdaptor)?.Receiver;
     SyntaxContextReceiver = (syntaxReceiver is SyntaxContextReceiverAdaptor) ? null : syntaxReceiver;
     CancellationToken     = cancellationToken;
     _additionalSources    = additionalSources;
     _diagnostics          = new DiagnosticBag();
 }
Example #5
0
        public NodeStateTable <TOutput> UpdateStateTable(DriverStateTable.Builder graphState, NodeStateTable <TOutput> previousTable, CancellationToken cancellationToken)
        {
            var sourceTable = graphState.GetLatestStateTableForNode(_source);

            if (sourceTable.IsCached)
            {
                return(previousTable);
            }

            var nodeTable = previousTable.ToBuilder();

            foreach (var entry in sourceTable)
            {
                if (entry.state == EntryState.Removed)
                {
                    nodeTable.RemoveEntries();
                }
                else if (entry.state != EntryState.Cached || !nodeTable.TryUseCachedEntries())
                {
                    // we don't currently handle modified any differently than added at the output
                    // we just run the action and mark the new source as added. In theory we could compare
                    // the diagnostics and sources produced and compare them, to see if they are any different
                    // than before.

                    var sourcesBuilder = new AdditionalSourcesCollection(_sourceExtension);
                    var diagnostics    = DiagnosticBag.GetInstance();

                    SourceProductionContext context = new SourceProductionContext(sourcesBuilder, diagnostics, cancellationToken);
                    try
                    {
                        _action(context, entry.item);
                        nodeTable.AddEntry((sourcesBuilder.ToImmutable(), diagnostics.ToReadOnly()), EntryState.Added);
                    }
                    finally
                    {
                        sourcesBuilder.Free();
                        diagnostics.Free();
                    }
                }
            }

            return(nodeTable.ToImmutableAndFree());
        }
 public void CopyTo(AdditionalSourcesCollection asc)
 {
     // we know the individual hint names are valid, but we do need to check that they
     // don't collide with any we already have
     if (asc._sourcesAdded.Count == 0)
     {
         asc._sourcesAdded.AddRange(this._sourcesAdded);
     }
     else
     {
         foreach (var source in this._sourcesAdded)
         {
             if (asc.Contains(source.HintName))
             {
                 throw new ArgumentException(string.Format(CodeAnalysisResources.HintNameUniquePerGenerator, source.HintName), "hintName");
             }
             asc._sourcesAdded.Add(source);
         }
     }
 }
Example #7
0
 internal EditContext(ImmutableArray <GeneratedSourceText> sources, CancellationToken cancellationToken = default)
 {
     AdditionalSources = new AdditionalSourcesCollection(sources);
     CancellationToken = cancellationToken;
 }
Example #8
0
 internal IncrementalGeneratorPostInitializationContext(AdditionalSourcesCollection additionalSources, CancellationToken cancellationToken)
 {
     AdditionalSources = additionalSources;
     CancellationToken = cancellationToken;
 }
Example #9
0
 internal SourceProductionContext(AdditionalSourcesCollection sources, DiagnosticBag diagnostics, CancellationToken cancellationToken)
 {
     CancellationToken = cancellationToken;
     Sources           = sources;
     Diagnostics       = diagnostics;
 }
Example #10
0
 internal GeneratorEditContext(AdditionalSourcesCollection sources, CancellationToken cancellationToken = default)
 {
     AdditionalSources = sources;
     CancellationToken = cancellationToken;
 }