Skip to content

Commit cb740f7

Browse files
committed
Throw if cancellation requested.
1 parent 607161d commit cb740f7

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/UnityUxmlGenerator/UxmlGenerator.Traits.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private static MemberDeclarationSyntax[] GetTraitsClassMembers(GeneratorExecutio
8181
typeToCast: IdentifierName(capture.ClassName)))
8282
};
8383

84-
initMethodBody.AddRange(GetAttributeValueAssignments(capture));
84+
initMethodBody.AddRange(GetAttributeValueAssignments(context, capture));
8585

8686
var initMethod = MethodWidget(
8787
identifier: "Init",
@@ -115,6 +115,8 @@ private static IEnumerable<MemberDeclarationSyntax> GetAttributeFields(Generator
115115

116116
foreach (var (property, uxmlAttributeDefaultValue) in capture.Properties)
117117
{
118+
context.CancellationToken.ThrowIfCancellationRequested();
119+
118120
fields.Add(GetAttributeFieldDeclaration(GetAttributeInfo(context, property, uxmlAttributeDefaultValue)));
119121
}
120122

@@ -222,12 +224,15 @@ private static FieldDeclarationSyntax GetAttributeFieldDeclaration(UxmlAttribute
222224
);
223225
}
224226

225-
private static IEnumerable<StatementSyntax> GetAttributeValueAssignments(UxmlTraitsCapture capture)
227+
private static IEnumerable<StatementSyntax> GetAttributeValueAssignments(GeneratorExecutionContext context,
228+
UxmlTraitsCapture capture)
226229
{
227230
var attributeValueAssignments = new List<StatementSyntax>();
228231

229232
foreach (var (property, _) in capture.Properties)
230233
{
234+
context.CancellationToken.ThrowIfCancellationRequested();
235+
231236
var propertyName = property.GetName();
232237
var fieldName = propertyName.ToPrivateFieldName();
233238

src/UnityUxmlGenerator/UxmlGenerator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,23 @@ public void Execute(GeneratorExecutionContext context)
2626
context.AddSource($"{nameof(UxmlElementClassName)}.g.cs", GenerateUxmlElementAttribute());
2727
context.AddSource($"{nameof(UxmlAttributeClassName)}.g.cs", GenerateUxmlAttributeAttribute());
2828

29-
if (context.SyntaxReceiver is not VisualElementReceiver receiver)
29+
if (context.SyntaxReceiver is not VisualElementReceiver receiver ||
30+
context.CancellationToken.IsCancellationRequested)
3031
{
3132
return;
3233
}
3334

3435
foreach (var uxmlElement in receiver.UxmlFactoryReceiver.Captures)
3536
{
37+
context.CancellationToken.ThrowIfCancellationRequested();
38+
3639
AddSource(context, uxmlElement, GenerateUxmlFactory(uxmlElement));
3740
}
3841

3942
foreach (var capture in receiver.UxmlTraitsReceiver.Captures)
4043
{
44+
context.CancellationToken.ThrowIfCancellationRequested();
45+
4146
AddSource(context, capture.Value, GenerateUxmlTraits(context, capture.Value));
4247
}
4348

0 commit comments

Comments
 (0)