Esempio n. 1
0
        public static async Task <Project> FormatProjectAsync(
            Project project,
            ISyntaxFactsService syntaxFacts,
            CodeFormatterOptions options,
            CancellationToken cancellationToken = default)
        {
            if (options == null)
            {
                options = CodeFormatterOptions.Default;
            }

            foreach (DocumentId documentId in project.DocumentIds)
            {
                Document document = project.GetDocument(documentId);

                if (options.IncludeGeneratedCode ||
                    !GeneratedCodeUtility.IsGeneratedCodeFile(document.FilePath))
                {
                    SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

                    if (options.IncludeGeneratedCode ||
                        !syntaxFacts.BeginsWithAutoGeneratedComment(root))
                    {
                        DocumentOptionSet optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

                        Document newDocument = await Formatter.FormatAsync(document, optionSet, cancellationToken).ConfigureAwait(false);

                        project = newDocument.Project;
                    }
                }
            }

            return(project);
        }