WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 30fe811

Browse files
committed
feature: add the ability to run a already generated source generator
1 parent 9227583 commit 30fe811

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/ReactiveMarbles.SourceGenerator.TestNuGetHelper/Compilation/SourceGeneratorUtility.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,73 @@ public T RunGenerator<T>(EventBuilderCompiler compiler, out ImmutableArray<Diagn
125125
return generator;
126126
}
127127

128+
/// <summary>
129+
/// Runs the generator.
130+
/// </summary>
131+
/// <param name="compiler">The compiler.</param>
132+
/// <param name="generator">The source generator instance.</param>
133+
/// <param name="compilationDiagnostics">The diagnostics which are produced from the compiler.</param>
134+
/// <param name="generatorDiagnostics">The diagnostics which are produced from the generator.</param>
135+
/// <param name="generatorDriver">Output value for the driver.</param>
136+
/// <param name="sources">The source code files.</param>
137+
/// <returns>The returned source generator instance.</returns>
138+
public ISourceGenerator RunGeneratorInstance(EventBuilderCompiler compiler, ISourceGenerator generator, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, params string[] sources) =>
139+
RunGeneratorInstance(compiler, generator, out compilationDiagnostics, out generatorDiagnostics, out generatorDriver, out _, out _, sources);
140+
141+
/// <summary>
142+
/// Runs the generator.
143+
/// </summary>
144+
/// <param name="compiler">The compiler.</param>
145+
/// <param name="generator">The source generator instance.</param>
146+
/// <param name="compilationDiagnostics">The diagnostics which are produced from the compiler.</param>
147+
/// <param name="generatorDiagnostics">The diagnostics which are produced from the generator.</param>
148+
/// <param name="generatorDriver">Output value for the driver.</param>
149+
/// <param name="sources">The source code files.</param>
150+
/// <returns>The returned source generator instance.</returns>
151+
public ISourceGenerator RunGeneratorInstance(EventBuilderCompiler compiler, ISourceGenerator generator, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, params (string FileName, string Source)[] sources) =>
152+
RunGeneratorInstance(compiler, generator, out compilationDiagnostics, out generatorDiagnostics, out generatorDriver, out _, out _, sources);
153+
154+
/// <summary>
155+
/// Runs the generator.
156+
/// </summary>
157+
/// <param name="compiler">The compiler.</param>
158+
/// <param name="generator">The source generator instance.</param>
159+
/// <param name="compilationDiagnostics">The diagnostics which are produced from the compiler.</param>
160+
/// <param name="generatorDiagnostics">The diagnostics which are produced from the generator.</param>
161+
/// <param name="generatorDriver">Output value for the driver.</param>
162+
/// <param name="beforeCompilation">The compilation before the generator has run.</param>
163+
/// <param name="afterGeneratorCompilation">The compilation after the generator has run.</param>
164+
/// <param name="sources">The source code files.</param>
165+
/// <returns>The returned source generator instance.</returns>
166+
public ISourceGenerator RunGeneratorInstance(EventBuilderCompiler compiler, ISourceGenerator generator, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, out Microsoft.CodeAnalysis.Compilation beforeCompilation, out Microsoft.CodeAnalysis.Compilation afterGeneratorCompilation, params string[] sources) =>
167+
RunGeneratorInstance(compiler, generator, out compilationDiagnostics, out generatorDiagnostics, out generatorDriver, out beforeCompilation, out afterGeneratorCompilation, sources.Select(x => (FileName: "Unknown File", Source: x)).ToArray());
168+
169+
/// <summary>
170+
/// Runs the generator.
171+
/// </summary>
172+
/// <param name="compiler">The compiler.</param>
173+
/// <param name="generator">The source generator instance.</param>
174+
/// <param name="compilationDiagnostics">The diagnostics which are produced from the compiler.</param>
175+
/// <param name="generatorDiagnostics">The diagnostics which are produced from the generator.</param>
176+
/// <param name="generatorDriver">Output value for the driver.</param>
177+
/// <param name="beforeCompilation">The compilation before the generator has run.</param>
178+
/// <param name="afterGeneratorCompilation">The compilation after the generator has run.</param>
179+
/// <param name="sources">The source code files.</param>
180+
/// <returns>The returned source generator instance.</returns>
181+
public ISourceGenerator RunGeneratorInstance(EventBuilderCompiler compiler, ISourceGenerator generator, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, out Microsoft.CodeAnalysis.Compilation beforeCompilation, out Microsoft.CodeAnalysis.Compilation afterGeneratorCompilation, params (string FileName, string Source)[] sources)
182+
{
183+
beforeCompilation = CreateCompilation(compiler, sources);
184+
185+
afterGeneratorCompilation = RunGenerators(beforeCompilation, out generatorDiagnostics, out generatorDriver, generator);
186+
187+
compilationDiagnostics = afterGeneratorCompilation.GetDiagnostics();
188+
189+
ShouldHaveNoCompilerDiagnosticsWarningOrAbove(_writeOutput, afterGeneratorCompilation, compilationDiagnostics);
190+
ShouldHaveNoCompilerDiagnosticsWarningOrAbove(_writeOutput, beforeCompilation, generatorDiagnostics);
191+
192+
return generator;
193+
}
194+
128195
/// <summary>
129196
/// Runs the generator.
130197
/// </summary>

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.2",
2+
"version": "1.3",
33
"publicReleaseRefSpec": [
44
"^refs/heads/master$",
55
"^refs/heads/main$"

0 commit comments

Comments
 (0)