@@ -42,13 +42,15 @@ public static class DocumentTransform
4242 /// <param name="projectDirectory">The path of the <c>.csproj</c> project file.</param>
4343 /// <param name="assemblyLoader">A function that can load an assembly with the given name.</param>
4444 /// <param name="progress">Reports warnings and errors in code generation.</param>
45+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
4546 /// <returns>A task whose result is the generated document.</returns>
4647 public static async Task < SyntaxTree > TransformAsync (
4748 CSharpCompilation compilation ,
4849 SyntaxTree inputDocument ,
4950 string projectDirectory ,
5051 Func < AssemblyName , Assembly > assemblyLoader ,
51- IProgress < Diagnostic > progress )
52+ IProgress < Diagnostic > progress ,
53+ CancellationToken cancellationToken )
5254 {
5355 Requires . NotNull ( compilation , nameof ( compilation ) ) ;
5456 Requires . NotNull ( inputDocument , nameof ( inputDocument ) ) ;
@@ -70,17 +72,19 @@ public static async Task<SyntaxTree> TransformAsync(
7072 var emittedAttributeLists = ImmutableArray < AttributeListSyntax > . Empty ;
7173 var emittedMembers = ImmutableArray < MemberDeclarationSyntax > . Empty ;
7274
73- var root = await inputDocument . GetRootAsync ( ) ;
75+ var root = await inputDocument . GetRootAsync ( cancellationToken ) ;
7476 var memberNodes = root
7577 . DescendantNodesAndSelf ( n => n is CompilationUnitSyntax || n is NamespaceDeclarationSyntax || n is TypeDeclarationSyntax )
7678 . OfType < CSharpSyntaxNode > ( ) ;
7779
7880 foreach ( var memberNode in memberNodes )
7981 {
82+ cancellationToken . ThrowIfCancellationRequested ( ) ;
8083 var attributeData = GetAttributeData ( compilation , inputSemanticModel , memberNode ) ;
8184 var generators = FindCodeGenerators ( attributeData , assemblyLoader ) ;
8285 foreach ( var generator in generators )
8386 {
87+ cancellationToken . ThrowIfCancellationRequested ( ) ;
8488 var context = new TransformationContext (
8589 memberNode ,
8690 inputSemanticModel ,
@@ -91,7 +95,7 @@ public static async Task<SyntaxTree> TransformAsync(
9195
9296 var richGenerator = generator as IRichCodeGenerator ?? new EnrichingCodeGeneratorProxy ( generator ) ;
9397
94- var emitted = await richGenerator . GenerateRichAsync ( context , progress , CancellationToken . None ) ;
98+ var emitted = await richGenerator . GenerateRichAsync ( context , progress , cancellationToken ) ;
9599
96100 emittedExterns = emittedExterns . AddRange ( emitted . Externs ) ;
97101 emittedUsings = emittedUsings . AddRange ( emitted . Usings ) ;
@@ -244,7 +248,7 @@ public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(
244248
245249 public async Task < RichGenerationResult > GenerateRichAsync ( TransformationContext context , IProgress < Diagnostic > progress , CancellationToken cancellationToken )
246250 {
247- var generatedMembers = await CodeGenerator . GenerateAsync ( context , progress , CancellationToken . None ) ;
251+ var generatedMembers = await CodeGenerator . GenerateAsync ( context , progress , cancellationToken ) ;
248252
249253 // Figure out ancestry for the generated type, including nesting types and namespaces.
250254 var wrappedMembers = context . ProcessingNode . Ancestors ( ) . Aggregate ( generatedMembers , WrapInAncestor ) ;
0 commit comments