public async Task <GeneratedCode> GenerateAsync(CancellationToken cancellationToken)
            {
                var root = SemanticDocument.Root;

                // should I check venus hidden position check here as well?
                root = root.ReplaceNode(
                    GetOutermostCallSiteContainerToProcess(cancellationToken),
                    await GenerateBodyForCallSiteContainerAsync(cancellationToken)
                    .ConfigureAwait(false)
                    );
                var callSiteDocument = await SemanticDocument
                                       .WithSyntaxRootAsync(root, cancellationToken)
                                       .ConfigureAwait(false);

                var newCallSiteRoot = callSiteDocument.Root;

                var codeGenerationService =
                    SemanticDocument.Document.GetLanguageService <ICodeGenerationService>();
                var result = GenerateMethodDefinition(LocalFunction, cancellationToken);

                SyntaxNode destination,
                           newContainer;

                if (LocalFunction)
                {
                    destination = InsertionPoint.With(callSiteDocument).GetContext();

                    // No valid location to insert the new method call.
                    if (destination == null)
                    {
                        return(await CreateGeneratedCodeAsync(
                                   OperationStatus.NoValidLocationToInsertMethodCall,
                                   callSiteDocument,
                                   cancellationToken
                                   )
                               .ConfigureAwait(false));
                    }

                    var localMethod = codeGenerationService.CreateMethodDeclaration(
                        method: result.Data,
                        options: new CodeGenerationOptions(
                            generateDefaultAccessibility: false,
                            generateMethodBodies: true,
                            options: Options,
                            parseOptions: destination?.SyntaxTree.Options
                            )
                        );
                    newContainer = codeGenerationService.AddStatements(
                        destination,
                        new[] { localMethod },
                        cancellationToken: cancellationToken
                        );
                }
                else
                {
                    var previousMemberNode = GetPreviousMember(callSiteDocument);

                    // it is possible in a script file case where there is no previous member. in that case, insert new text into top level script
                    destination  = previousMemberNode.Parent ?? previousMemberNode;
                    newContainer = codeGenerationService.AddMethod(
                        destination,
                        result.Data,
                        new CodeGenerationOptions(
                            afterThisLocation: previousMemberNode.GetLocation(),
                            generateDefaultAccessibility: true,
                            generateMethodBodies: true,
                            options: Options
                            ),
                        cancellationToken
                        );
                }

                var newSyntaxRoot = newCallSiteRoot.ReplaceNode(destination, newContainer);
                var newDocument   = callSiteDocument.Document.WithSyntaxRoot(newSyntaxRoot);

                newDocument = await Simplifier
                              .ReduceAsync(newDocument, Simplifier.Annotation, null, cancellationToken)
                              .ConfigureAwait(false);

                var generatedDocument = await SemanticDocument
                                        .CreateAsync(newDocument, cancellationToken)
                                        .ConfigureAwait(false);

                // For nullable reference types, we can provide a better experience by reducing use
                // of nullable reference types after a method is done being generated. If we can
                // determine that the method never returns null, for example, then we can
                // make the signature into a non-null reference type even though
                // the original type was nullable. This allows our code generation to
                // follow our recommendation of only using nullable when necessary.
                // This is done after method generation instead of at analyzer time because it's purely
                // based on the resulting code, which the generator can modify as needed. If return statements
                // are added, the flow analysis could change to indicate something different. It's cleaner to rely
                // on flow analysis of the final resulting code than to try and predict from the analyzer what
                // will happen in the generator.
                var finalDocument = await UpdateMethodAfterGenerationAsync(
                    generatedDocument,
                    result,
                    cancellationToken
                    )
                                    .ConfigureAwait(false);

                var finalRoot = finalDocument.Root;

                var methodDefinition = finalRoot
                                       .GetAnnotatedNodesAndTokens(MethodDefinitionAnnotation)
                                       .FirstOrDefault();

                if (!methodDefinition.IsNode || methodDefinition.AsNode() == null)
                {
                    return(await CreateGeneratedCodeAsync(
                               result.Status.With(OperationStatus.FailedWithUnknownReason),
                               finalDocument,
                               cancellationToken
                               )
                           .ConfigureAwait(false));
                }

                if (
                    methodDefinition.SyntaxTree.IsHiddenPosition(
                        methodDefinition.AsNode().SpanStart,
                        cancellationToken
                        ) ||
                    methodDefinition.SyntaxTree.IsHiddenPosition(
                        methodDefinition.AsNode().Span.End,
                        cancellationToken
                        )
                    )
                {
                    return(await CreateGeneratedCodeAsync(
                               result.Status.With(OperationStatus.OverlapsHiddenPosition),
                               finalDocument,
                               cancellationToken
                               )
                           .ConfigureAwait(false));
                }

                return(await CreateGeneratedCodeAsync(
                           result.Status,
                           finalDocument,
                           cancellationToken
                           )
                       .ConfigureAwait(false));
            }