Skip to content

Commit 9d037ad

Browse files
committed
source code generator now aborts if there are errors in Actions.
Previously invalid yarn actions would still get processed and codegen to register them would happen. The idea being we could flag "hey we know there is an action but it's in a bad state". However this could cause compilation errors in the generated source code which is quite annoying to deal with. So now warning still get to slip through and generate a "hey this has issues", but errors do not.
1 parent 63c52e0 commit 9d037ad

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Editor/Analysis/ActionsRegistrationGenerator~/ActionsGenerator.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public void Execute(GeneratorExecutionContext context)
117117
output.WriteLine($"Unable to determine project location on disk. Settings values will be ignored and codegen will occur");
118118
}
119119

120+
bool hasCriticalActionErrors = false;
120121
try
121122
{
122123
output.WriteLine("Source code generation for assembly " + context.Compilation.AssemblyName);
@@ -188,7 +189,6 @@ public void Execute(GeneratorExecutionContext context)
188189
{
189190
output.WriteLine($"Not generating registration code for {context.Compilation.AssemblyName}: we've been told to exclude it, because its name begins with one of these prefixes: {string.Join(", ", prefixesToIgnore)}");
190191
return;
191-
192192
}
193193

194194
if (!(context.Compilation is CSharpCompilation compilation))
@@ -227,14 +227,14 @@ public void Execute(GeneratorExecutionContext context)
227227
{
228228
output.WriteLine($"Flagging '{action.Name}' ({action.MethodName}): {diagnostic}");
229229
action.ContainsErrors = true;
230+
231+
if (diagnostic.Severity == DiagnosticSeverity.Error)
232+
{
233+
hasCriticalActionErrors = true;
234+
}
230235
}
231236
}
232237

233-
if (diagnostics.Count > 0)
234-
{
235-
continue;
236-
}
237-
238238
// Commands are parsed as whitespace, so spaces in the command name
239239
// would render the command un-callable.
240240
if (action.Name.Any(x => Char.IsWhiteSpace(x)))
@@ -261,6 +261,13 @@ public void Execute(GeneratorExecutionContext context)
261261
output.WriteLine($"Action {action.Name}: {action.SourceFileName}:{action.Declaration?.GetLocation()?.GetLineSpan().StartLinePosition.Line} ({action.Type})");
262262
}
263263

264+
if (hasCriticalActionErrors)
265+
{
266+
stopwatch.Stop();
267+
output.WriteLine($"Critical issues were encountered in the actions, aborting code generation, stopping analysis after {stopwatch.Elapsed.TotalMilliseconds}ms");
268+
return;
269+
}
270+
264271
output.Write($"Generating source code...");
265272

266273
var source = Analyser.GenerateRegistrationFileSource(actions);
512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)