public static Task <Document> RefactorAsync( Document document, LocalFunctionStatementSyntax localFunction, bool copyAfter = true, CancellationToken cancellationToken = default) { StatementListInfo statementsInfos = SyntaxInfo.StatementListInfo(localFunction); SyntaxList <StatementSyntax> statements = statementsInfos.Statements; int index = statements.IndexOf(localFunction); if (index == 0) { if (copyAfter) { if (statementsInfos.ParentAsBlock.OpenBraceToken.GetFullSpanEndLine() == localFunction.GetFullSpanStartLine()) { localFunction = localFunction.WithLeadingTrivia(localFunction.GetLeadingTrivia().Insert(0, NewLine())); } } else { localFunction = localFunction.WithTrailingTrivia(localFunction.GetTrailingTrivia().Add(NewLine())); } } int insertIndex = (copyAfter) ? index + 1 : index; SyntaxList <StatementSyntax> newStatements = statements.Insert(insertIndex, localFunction.WithNavigationAnnotation()); return(document.ReplaceStatementsAsync(statementsInfos, newStatements, cancellationToken)); }