|
7 | 7 | using System.Collections.Immutable; |
8 | 8 | using System.IO; |
9 | 9 | using System.Linq; |
| 10 | + |
10 | 11 | using Microsoft.CodeAnalysis; |
11 | 12 | using Microsoft.CodeAnalysis.CSharp; |
12 | 13 |
|
@@ -64,18 +65,33 @@ static SourceGeneratorUtility() |
64 | 65 | /// <param name="sources">The source code files.</param> |
65 | 66 | /// <returns>The source generator instance.</returns> |
66 | 67 | public T RunGenerator<T>(EventBuilderCompiler compiler, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, params string[] sources) |
| 68 | + where T : ISourceGenerator, new() => RunGenerator<T>(compiler, out compilationDiagnostics, out generatorDiagnostics, out generatorDriver, out _, out _, sources); |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Runs the generator. |
| 72 | + /// </summary> |
| 73 | + /// <typeparam name="T">The type of generator.</typeparam> |
| 74 | + /// <param name="compiler">The compiler.</param> |
| 75 | + /// <param name="compilationDiagnostics">The diagnostics which are produced from the compiler.</param> |
| 76 | + /// <param name="generatorDiagnostics">The diagnostics which are produced from the generator.</param> |
| 77 | + /// <param name="generatorDriver">Output value for the driver.</param> |
| 78 | + /// <param name="beforeCompilation">The compilation before the generator has run.</param> |
| 79 | + /// <param name="afterGeneratorCompilation">The compilation after the generator has run.</param> |
| 80 | + /// <param name="sources">The source code files.</param> |
| 81 | + /// <returns>The source generator instance.</returns> |
| 82 | + public T RunGenerator<T>(EventBuilderCompiler compiler, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, out Microsoft.CodeAnalysis.Compilation beforeCompilation, out Microsoft.CodeAnalysis.Compilation afterGeneratorCompilation, params string[] sources) |
67 | 83 | where T : ISourceGenerator, new() |
68 | 84 | { |
69 | | - var compilation = CreateCompilation(compiler, sources); |
| 85 | + beforeCompilation = CreateCompilation(compiler, sources); |
70 | 86 |
|
71 | 87 | var generator = new T(); |
72 | 88 |
|
73 | | - var newCompilation = RunGenerators(compilation, out generatorDiagnostics, out generatorDriver, generator); |
| 89 | + afterGeneratorCompilation = RunGenerators(beforeCompilation, out generatorDiagnostics, out generatorDriver, generator); |
74 | 90 |
|
75 | | - compilationDiagnostics = newCompilation.GetDiagnostics(); |
| 91 | + compilationDiagnostics = afterGeneratorCompilation.GetDiagnostics(); |
76 | 92 |
|
77 | | - ShouldHaveNoCompilerDiagnosticsWarningOrAbove(_writeOutput, newCompilation, compilationDiagnostics); |
78 | | - ShouldHaveNoCompilerDiagnosticsWarningOrAbove(_writeOutput, compilation, generatorDiagnostics); |
| 93 | + ShouldHaveNoCompilerDiagnosticsWarningOrAbove(_writeOutput, afterGeneratorCompilation, compilationDiagnostics); |
| 94 | + ShouldHaveNoCompilerDiagnosticsWarningOrAbove(_writeOutput, beforeCompilation, generatorDiagnostics); |
79 | 95 |
|
80 | 96 | return generator; |
81 | 97 | } |
|
0 commit comments